<!DOCTYPE html>


<html lang="en">
  

    <head>
      <meta charset="utf-8" />
        
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title> 朝花夕拾</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/ww.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      
<link rel="stylesheet" href="/css/fonts/remixicon.css">

      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.staticfile.org/pace/1.2.4/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    </head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      
<section class="cover">
    
  <div class="cover-frame">
    <div class="bg-box">
      <img src="/images/cover8.jpg" alt="image frame" />
    </div>
    <div class="cover-inner text-center text-white">
      <h1><a href="/">朝花夕拾</a></h1>
      <div id="subtitle-box">
        
        <span id="subtitle"></span>
        
      </div>
      <div>
        
      </div>
    </div>
  </div>
  <div class="cover-learn-more">
    <a href="javascript:void(0)" class="anchor"><i class="ri-arrow-down-line"></i></a>
  </div>
</section>



<script src="https://cdn.staticfile.org/typed.js/2.0.12/typed.min.js"></script>


<!-- Subtitle -->

  <script>
    try {
      var typed = new Typed("#subtitle", {
        strings: ['', '', ''],
        startDelay: 0,
        typeSpeed: 200,
        loop: true,
        backSpeed: 100,
        showCursor: true
      });
    } catch (err) {
      console.log(err)
    }
  </script>
  
<div id="main">
  <section class="outer">
  
  
  

<div class="notice" style="margin-top:50px">
    <i class="ri-heart-fill"></i>
    <div class="notice-content" id="broad"></div>
</div>
<script type="text/javascript">
    fetch('https://v1.hitokoto.cn')
        .then(response => response.json())
        .then(data => {
            document.getElementById("broad").innerHTML = data.hitokoto;
        })
        .catch(console.error)
</script>

<style>
    .notice {
        padding: 20px;
        border: 1px dashed #e6e6e6;
        color: #969696;
        position: relative;
        display: inline-block;
        width: 100%;
        background: #fbfbfb50;
        border-radius: 10px;
    }

    .notice i {
        float: left;
        color: #999;
        font-size: 16px;
        padding-right: 10px;
        vertical-align: middle;
        margin-top: -2px;
    }

    .notice-content {
        display: initial;
        vertical-align: middle;
    }
</style>
  
  <article class="articles">
    
    
    
    
    <article
  id="post-MyBlog服务启动和windows软件调用"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/MyBlog%E6%9C%8D%E5%8A%A1%E5%90%AF%E5%8A%A8%E5%92%8Cwindows%E8%BD%AF%E4%BB%B6%E8%B0%83%E7%94%A8/"
    >MyBlog服务启动和windows软件调用</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/MyBlog%E6%9C%8D%E5%8A%A1%E5%90%AF%E5%8A%A8%E5%92%8Cwindows%E8%BD%AF%E4%BB%B6%E8%B0%83%E7%94%A8/" class="article-date">
  <time datetime="2023-05-10T00:45:00.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Env/">Env</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="MyBlog服务启动和windows软件调用"><a href="#MyBlog服务启动和windows软件调用" class="headerlink" title="MyBlog服务启动和windows软件调用"></a>MyBlog服务启动和windows软件调用</h1><h2 id="修改Tomcat主页"><a href="#修改Tomcat主页" class="headerlink" title="修改Tomcat主页"></a>修改Tomcat主页</h2><p>D:\VSCodeSrc\apache-tomcat-8.5.78\webapps\ROOT\index.jsp</p>
<p>把index.jsp 备份一下，</p>
<p>重新创建一个index.jsp,</p>
<p>内容如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;icon&quot;</span> <span class="attr">href</span>=<span class="string">&quot;http://www.wangwei.com:8080/faviconWei.ico&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;/jquery.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>服务管理<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;myBlogTomcat://&quot;</span> <span class="attr">target</span>=<span class="string">&quot;_blank&quot;</span> <span class="attr">type</span>=<span class="string">&quot;success&quot;</span> <span class="attr">round</span>&gt;</span>To Running myBlogTomcat <span class="tag">&lt;/<span class="name">a</span>&gt;</span>	</span><br><span class="line">		<span class="tag">&lt;/<span class="name">li</span>&gt;</span>	<span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;myBlogGolang://&quot;</span> <span class="attr">target</span>=<span class="string">&quot;_blank&quot;</span> <span class="attr">type</span>=<span class="string">&quot;success&quot;</span> <span class="attr">round</span>&gt;</span>To Running myBlogGolang <span class="tag">&lt;/<span class="name">a</span>&gt;</span>	</span><br><span class="line">		<span class="tag">&lt;/<span class="name">li</span>&gt;</span>	<span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;myBlogFTP://&quot;</span> <span class="attr">target</span>=<span class="string">&quot;_blank&quot;</span> <span class="attr">type</span>=<span class="string">&quot;success&quot;</span> <span class="attr">round</span>&gt;</span>To Running myBlogFTP <span class="tag">&lt;/<span class="name">a</span>&gt;</span>	</span><br><span class="line">		<span class="tag">&lt;/<span class="name">li</span>&gt;</span>	<span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;myBlogVue://&quot;</span> <span class="attr">target</span>=<span class="string">&quot;_blank&quot;</span> <span class="attr">type</span>=<span class="string">&quot;success&quot;</span> <span class="attr">round</span>&gt;</span>To Running yBlogVue <span class="tag">&lt;/<span class="name">a</span>&gt;</span>	</span><br><span class="line">		<span class="tag">&lt;/<span class="name">li</span>&gt;</span>	<span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;http://www.wangwei.com:8082&quot;</span> <span class="attr">target</span>=<span class="string">&quot;_blank&quot;</span> <span class="attr">type</span>=<span class="string">&quot;success&quot;</span> <span class="attr">round</span>&gt;</span>To Join In My City of Sky <span class="tag">&lt;/<span class="name">a</span>&gt;</span>	</span><br><span class="line">		<span class="tag">&lt;/<span class="name">li</span>&gt;</span>	<span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>





<h2 id="windows-开机启动bat："><a href="#windows-开机启动bat：" class="headerlink" title="windows 开机启动bat："></a>windows 开机启动bat：</h2><pre><code>按键盘上的`Windows + R`键以打开`运行`,然后键入 taskschd.msc ,最后，单击或点击`确定`。

创建一个基本任务即可。
</code></pre>
<h2 id="bat命令目录准备：-weiCommand"><a href="#bat命令目录准备：-weiCommand" class="headerlink" title="bat命令目录准备： weiCommand"></a>bat命令目录准备： weiCommand</h2><p>D:\VSCodeSrc\apache-tomcat-8.5.78\webapps\weiCommand</p>
<p>说明：这些命令文件备份在Vue发版目录，请将这个目录文件复到webapps目录下。</p>
<h2 id="修改windows注册表：for-weiCommand"><a href="#修改windows注册表：for-weiCommand" class="headerlink" title="修改windows注册表：for weiCommand"></a>修改windows注册表：for weiCommand</h2><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\WeiOpenProject]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\WeiOpenProject.bat&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiOpenProject\DefaultIcon]</span><br><span class="line">@=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\WeiOpenProject.bat&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiOpenProject\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiOpenProject\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiOpenProject\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\WeiOpenProject.bat\&quot;&quot;</span><br><span class="line"></span><br><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogTomcat]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">1</span> - <span class="number">8080</span>- Tomcat .bat&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogTomcat\DefaultIcon]</span><br><span class="line">@=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">1</span> - <span class="number">8080</span>- Tomcat .bat&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogTomcat\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogTomcat\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogTomcat\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">1</span> - <span class="number">8080</span>- Tomcat .bat\&quot;&quot;</span><br><span class="line"></span><br><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogGolang]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">2</span> - <span class="number">8081</span>- myBlogGolang.bat&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogGolang\DefaultIcon]</span><br><span class="line">@=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">2</span> - <span class="number">8081</span>- myBlogGolang.bat&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogGolang\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogGolang\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogGolang\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">2</span> - <span class="number">8081</span>- myBlogGolang.bat\&quot;&quot;</span><br><span class="line"></span><br><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogFTP]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">3</span> - <span class="number">2121</span>- FTP .bat&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogFTP\DefaultIcon]</span><br><span class="line">@=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">3</span> - <span class="number">2121</span>- FTP .bat&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogFTP\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogFTP\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogFTP\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">3</span> - <span class="number">2121</span>- FTP .bat\&quot;&quot;</span><br><span class="line"></span><br><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogVue]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">4</span> - <span class="number">8082</span>- Vue.bat&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogVue\DefaultIcon]</span><br><span class="line">@=&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">4</span> - <span class="number">8082</span>- Vue.bat&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogVue\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogVue\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\myBlogVue\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\VSCodeSrc\\apache-tomcat-<span class="number">8</span>.<span class="number">5</span>.<span class="number">78</span>\\webapps\\weiCommand\\<span class="number">4</span> - <span class="number">8082</span>- Vue.bat\&quot;&quot;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="修改windows注册表：for-Vue-myBlog"><a href="#修改windows注册表：for-Vue-myBlog" class="headerlink" title="修改windows注册表：for Vue-myBlog"></a>修改windows注册表：for Vue-myBlog</h2><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\WeiFilezilla]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;C:\\Program Files\\FileZilla FTP Client\\filezilla.exe&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiFilezilla\DefaultIcon]</span><br><span class="line">@=&quot;C:\\Program Files\\FileZilla FTP Client\\filezilla.exe&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiFilezilla\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiFilezilla\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiFilezilla\shell\open\command]</span><br><span class="line">@=&quot;\&quot;C:\\Program Files\\FileZilla FTP Client\\filezilla.exe\&quot;&quot;</span><br><span class="line"></span><br><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\WeiListen1]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\Program Files\\Listen1\\Listen1.exe&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiListen1\DefaultIcon]</span><br><span class="line">@=&quot;D:\\Program Files\\Listen1\\Listen1.exe&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiListen1\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiListen1\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiListen1\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\Program Files\\Listen1\\Listen1.exe\&quot;&quot;</span><br><span class="line"></span><br><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\WeiTypora]</span><br><span class="line">&quot;URL Protocol&quot;=&quot;D:\\install\\Typora\\Typora.exe&quot;</span><br><span class="line">@=&quot;Piep Protocol&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiTypora\DefaultIcon]</span><br><span class="line">@=&quot;D:\\install\\Typora\\Typora.exe&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiTypora\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiTypora\shell\open]</span><br><span class="line">[HKEY_CLASSES_ROOT\WeiTypora\shell\open\command]</span><br><span class="line">@=&quot;\&quot;D:\\install\\Typora\\Typora.exe\&quot;&quot;</span><br><span class="line"></span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/javascript/" rel="tag">javascript</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/web/" rel="tag">web</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/windows/" rel="tag">windows</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-测试-开启jmeter测试"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/10/%E6%B5%8B%E8%AF%95-%E5%BC%80%E5%90%AFjmeter%E6%B5%8B%E8%AF%95/"
    >测试-开启jmeter测试</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/10/%E6%B5%8B%E8%AF%95-%E5%BC%80%E5%90%AFjmeter%E6%B5%8B%E8%AF%95/" class="article-date">
  <time datetime="2023-05-10T00:43:26.000Z" itemprop="datePublished">2023-05-10</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="jmeter"><a href="#jmeter" class="headerlink" title="jmeter"></a>jmeter</h1><h2 id="官网"><a href="#官网" class="headerlink" title="官网"></a>官网</h2><p><a target="_blank" rel="noopener" href="https://jmeter.apache.org/">https://jmeter.apache.org/</a></p>
<h2 id="下载jmeter"><a href="#下载jmeter" class="headerlink" title="下载jmeter"></a>下载jmeter</h2><p>Apache JMeter 5.5 (Requires Java 8+)</p>
<h5 id="Binaries"><a href="#Binaries" class="headerlink" title="Binaries"></a>Binaries</h5><table>
<thead>
<tr>
<th><a target="_blank" rel="noopener" href="https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.tgz">apache-jmeter-5.5.tgz</a></th>
<th><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/binaries/apache-jmeter-5.5.tgz.sha512">sha512</a></th>
<th><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/binaries/apache-jmeter-5.5.tgz.asc">pgp</a></th>
</tr>
</thead>
<tbody><tr>
<td><a target="_blank" rel="noopener" href="https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.zip">apache-jmeter-5.5.zip</a></td>
<td><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/binaries/apache-jmeter-5.5.zip.sha512">sha512</a></td>
<td><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/binaries/apache-jmeter-5.5.zip.asc">pgp</a></td>
</tr>
</tbody></table>
<h5 id="Source"><a href="#Source" class="headerlink" title="Source"></a>Source</h5><table>
<thead>
<tr>
<th><a target="_blank" rel="noopener" href="https://dlcdn.apache.org//jmeter/source/apache-jmeter-5.5_src.tgz">apache-jmeter-5.5_src.tgz</a></th>
<th><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/source/apache-jmeter-5.5_src.tgz.sha512">sha512</a></th>
<th><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/source/apache-jmeter-5.5_src.tgz.asc">pgp</a></th>
</tr>
</thead>
<tbody><tr>
<td><a target="_blank" rel="noopener" href="https://dlcdn.apache.org//jmeter/source/apache-jmeter-5.5_src.zip">apache-jmeter-5.5_src.zip</a></td>
<td><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/source/apache-jmeter-5.5_src.zip.sha512">sha512</a></td>
<td><a target="_blank" rel="noopener" href="https://www.apache.org/dist/jmeter/source/apache-jmeter-5.5_src.zip.asc">pgp</a></td>
</tr>
</tbody></table>
<h2 id="下载jmeter-tps插件"><a href="#下载jmeter-tps插件" class="headerlink" title="下载jmeter tps插件"></a>下载jmeter tps插件</h2><p>第一步：下次Jmeter插件（<a target="_blank" rel="noopener" href="https://link.jianshu.com/?t=https://jmeter-plugins.org/wiki/TransactionsPerSecond/">https://jmeter-plugins.org/wiki/TransactionsPerSecond/</a>）</p>
<p>第二步：下载之后解压，将解压后的lib包覆盖到Jmeter目录下的lib目录</p>
<p>第三步：重启Jmeter，就可以看到有了tps的监听</p>
<p><strong>方法二：</strong></p>
<p>获取插件的最简单方法是安装 <a target="_blank" rel="noopener" href="https://jmeter-plugins.org/wiki/PluginsManager/">Plugins Manager </a>。 然后，您只需单击复选框即可安装任何其他插件。 </p>
<p> 下载 **<a target="_blank" rel="noopener" href="https://jmeter-plugins.org/get/">plugins-manager.jar </a>**并放入 <code>lib/ext </code>目录，然后重启 JMeter。   然后搜索插件： 3 Basic Graph 。 </p>
<p><strong>方法三：</strong></p>
<p>直接把 D:\01.GBase\2022GBASE工作记录\01.项目记录\00.技术\tpcc\jmeter 目录下的2个jar包放入<code>lib/ext </code>目录下即可。</p>
<h1 id="测试任务"><a href="#测试任务" class="headerlink" title="测试任务"></a>测试任务</h1><p>描述： </p>
<p>​		插入、</p>
<p>​		主键&#x2F;索引单点查询、</p>
<p>​		主键&#x2F;索引多点查询、</p>
<p>​		主键&#x2F;索引的范围查询、</p>
<p>​		主键&#x2F;索引更新、</p>
<p>​		OLTP混合读写；</p>
<p>​		输出qps、tps、时延(95% avg max)报告</p>
<p>说明：</p>
<p>​		表行数：3000w  ,</p>
<p>​		执行时长：10分钟以上,</p>
<p>​		并发数8，16，32，64，128，256 </p>
<h2 id="基础表准备-表结构和存储过程"><a href="#基础表准备-表结构和存储过程" class="headerlink" title="基础表准备-表结构和存储过程"></a>基础表准备-表结构和存储过程</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> if <span class="keyword">exists</span> t;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> t(</span><br><span class="line">    id	 serial <span class="keyword">not</span> <span class="keyword">null</span>,</span><br><span class="line">	col1 datetime <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span> <span class="keyword">default</span> <span class="keyword">current</span> <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span>,</span><br><span class="line">    col2 <span class="type">char</span>(<span class="number">200</span>),</span><br><span class="line">    col3 <span class="type">varchar</span>(<span class="number">200</span>),</span><br><span class="line">    <span class="keyword">primary</span> key (id)</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">procedure</span> if <span class="keyword">exists</span> insert_t;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">procedure</span> insert_t()</span><br><span class="line">	<span class="keyword">define</span> i <span class="type">int</span>;</span><br><span class="line">	<span class="keyword">for</span> i<span class="operator">=</span><span class="number">1</span> <span class="keyword">to</span> <span class="number">30000</span></span><br><span class="line">		<span class="keyword">insert</span> <span class="keyword">into</span> t(col2,col3) <span class="keyword">values</span> (<span class="string">&#x27;zgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8l&#x27;</span>,<span class="string">&#x27;7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8F&#x27;</span>);</span><br><span class="line">	<span class="keyword">end</span> <span class="keyword">for</span>;</span><br><span class="line"><span class="keyword">end</span> <span class="keyword">procedure</span>;</span><br></pre></td></tr></table></figure>



<h2 id="执行存储过程插入3千万行数据"><a href="#执行存储过程插入3千万行数据" class="headerlink" title="执行存储过程插入3千万行数据"></a>执行存储过程插入3千万行数据</h2><h5 id="insert3000w"><a href="#insert3000w" class="headerlink" title="insert3000w"></a>insert3000w</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">echo &quot;call insert_t();&quot; | dbaccess tpcc </span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">echo &quot;select count(col1) sum from t;&quot; |dbaccess tpcc</span><br></pre></td></tr></table></figure>



<h2 id="测试插入"><a href="#测试插入" class="headerlink" title="测试插入"></a>测试插入</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">insert into t(col2,col3) values (&#x27;zgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8l&#x27;,&#x27;7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8F&#x27;);</span><br></pre></td></tr></table></figure>



<h2 id="测试主键-x2F-索引单点查询"><a href="#测试主键-x2F-索引单点查询" class="headerlink" title="测试主键&#x2F;索引单点查询"></a>测试主键&#x2F;索引单点查询</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from t where id = $&#123;idid&#125;;</span><br></pre></td></tr></table></figure>



<h2 id="测试主键-x2F-索引多点查询"><a href="#测试主键-x2F-索引多点查询" class="headerlink" title="测试主键&#x2F;索引多点查询"></a>测试主键&#x2F;索引多点查询</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from t where id in ($&#123;id1&#125;,$&#123;id2&#125;,$&#123;id3&#125;,$&#123;id4&#125;,$&#123;id5&#125;,$&#123;id6&#125;,$&#123;id7&#125;,$&#123;id8&#125;,$&#123;id9&#125;,$&#123;id10&#125;);</span><br></pre></td></tr></table></figure>



<h2 id="测试主键-x2F-索引的范围查询"><a href="#测试主键-x2F-索引的范围查询" class="headerlink" title="测试主键&#x2F;索引的范围查询"></a>测试主键&#x2F;索引的范围查询</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from t where id &gt; $&#123;idid&#125; and id &lt; $&#123;idid&#125;+10 ;</span><br></pre></td></tr></table></figure>



<h2 id="测试主键-x2F-索引更新"><a href="#测试主键-x2F-索引更新" class="headerlink" title="测试主键&#x2F;索引更新"></a>测试主键&#x2F;索引更新</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">update t set col2=&#x27;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&#x27; where id = $&#123;idid&#125;</span><br></pre></td></tr></table></figure>



<h2 id="测试OLTP混合读写"><a href="#测试OLTP混合读写" class="headerlink" title="测试OLTP混合读写"></a>测试OLTP混合读写</h2><p>建立5个JDBC Reuqest</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">insert into t(col2,col3) values (&#x27;zgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8FDBZ7dkBUdX8l&#x27;,&#x27;7dkBUdX8liWERZzgCdw31DZpyToUdqrszWXt8F&#x27;);</span><br><span class="line">select * from t where id = $&#123;idid&#125;;</span><br><span class="line">select * from t where id in ($&#123;id1&#125;,$&#123;id2&#125;,$&#123;id3&#125;,$&#123;id4&#125;,$&#123;id5&#125;,$&#123;id6&#125;,$&#123;id7&#125;,$&#123;id8&#125;,$&#123;id9&#125;,$&#123;id10&#125;);</span><br><span class="line">select * from t where id &gt; $&#123;idid&#125; and id &lt; $&#123;idid&#125;+10 ;</span><br><span class="line">update t set col2=&#x27;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&#x27; where id = $&#123;idid&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/jmeter/" rel="tag">jmeter</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-正则表达式GolangPythonJavascript"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/09/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8FGolangPythonJavascript/"
    >正则表达式GolangPythonJavascript</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/09/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8FGolangPythonJavascript/" class="article-date">
  <time datetime="2023-05-09T13:57:22.000Z" itemprop="datePublished">2023-05-09</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Golang/">Golang</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h3 id="Golang"><a href="#Golang" class="headerlink" title="Golang"></a>Golang</h3><p><a target="_blank" rel="noopener" href="https://juejin.cn/post/7090196238955446285">Golang</a><br>regexp.MatchString(“.even”, word)</p>
<h3 id="Python"><a href="#Python" class="headerlink" title="Python"></a>Python</h3><p><a target="_blank" rel="noopener" href="https://www.runoob.com/python/python-reg-expressions.html">Python</a><br>re.match(pattern, string, flags&#x3D;0)</p>
<h3 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h3><p><a target="_blank" rel="noopener" href="https://www.runoob.com/js/js-regexp.html">JavaScript</a><br>str.search(&#x2F;Runoob&#x2F;i); 说明,i 是不区分大小写</p>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>在计算中，我们经常需要将特定模式的字符或字符子集匹配为另一个字符串中的字符串。此技术用于使用特别的语法来搜索给定字符串中的特定字符集。比如邮件、手机号、身份证号等等。</p>
<p>如果搜索到的模式匹配，或者在目标字符串中找到给定的子集，则搜索被称为成功；否则被认为是不成功的。</p>
<p>那么此时该用到正则表达式了。</p>
<h2 id="什么是正则表达式"><a href="#什么是正则表达式" class="headerlink" title="什么是正则表达式"></a>什么是正则表达式</h2><p><strong>正则表达式</strong>（或 RegEx）是一个特殊的字符序列，它定义了用于匹配特定文本的搜索模式。在 Golang 中，有一个内置的正则表达式包: <code>regexp</code> 包，其中包含所有操作列表，如过滤、修改、替换、验证或提取。</p>
<p>正则表达式可以用于文本搜索和更高级的文本操作。正则表达式内置于 grep 和 sed 等工具，vi 和 emacs 等文本编辑器，Go、Java 和 Python 等编程语言中。表达式的语法主要遵循这些流行语言中使用的已建立的 RE2 语法。 <a href="https://link.juejin.cn/?target=https://github.com/google/re2/wiki/Syntax">RE2</a> 语法是 PCRE 的一个子集，有各种注意事项。</p>
<p>以下是正则表达式模式表格：</p>
<table>
<thead>
<tr>
<th>Regex</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td><code>.</code></td>
<td>匹配任何单一字符</td>
</tr>
<tr>
<td><code>?</code></td>
<td>匹配前面的元素一次要么根本不匹配。</td>
</tr>
<tr>
<td><code>+</code></td>
<td>匹配前面的元素一次或多次。</td>
</tr>
<tr>
<td><code>*</code></td>
<td>匹配前一个元素的零次或多次。</td>
</tr>
<tr>
<td><code>^</code></td>
<td>匹配字符串中的起始位置。</td>
</tr>
<tr>
<td><code>$</code></td>
<td>匹配字符串中的结束位置。</td>
</tr>
<tr>
<td>&#96;</td>
<td>&#96;</td>
</tr>
<tr>
<td><code>[abc]</code></td>
<td>匹配 a 或 b，或 c。</td>
</tr>
<tr>
<td><code>[a-c]</code></td>
<td>a-c 的范围; 匹配 a 或 b，或 c。</td>
</tr>
<tr>
<td><code>[^abc]</code></td>
<td>否定, 匹配除 a，或 b，或 c之外的一切。</td>
</tr>
<tr>
<td><code>\s</code></td>
<td>匹配空格字符。</td>
</tr>
<tr>
<td><code>\w</code></td>
<td>匹配一个单词字符；等同于 <code>[a-zA-Z_0-9]</code></td>
</tr>
</tbody></table>
<p>Go 语言的 <code>regexp</code> 包中有几个典型的函数：</p>
<ul>
<li><code>MatchString()</code></li>
<li><code> Compile()</code></li>
<li><code>FindString()</code></li>
<li><code>FindAllString()</code></li>
<li><code>FindStringIndex()</code></li>
<li><code>FindAllStringIndex()</code></li>
<li><code>FindStringSubmatch()</code></li>
<li><code>Split()</code></li>
<li><code>ReplaceAllString</code></li>
<li><code>ReplaceAllStringFunc()</code></li>
</ul>
<h2 id="MatchString-函数"><a href="#MatchString-函数" class="headerlink" title="MatchString 函数"></a>MatchString 函数</h2><p><code>MatchString()</code> 函数用来匹配子字符串，下面的程序用来匹配是否是 <strong>一个字母后跟着 even 字符</strong>，正则模式为： <code>.even</code>。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;log&quot;</span></span><br><span class="line">	<span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">	words := [...]<span class="type">string</span>&#123;<span class="string">&quot;Seven&quot;</span>, <span class="string">&quot;even&quot;</span>, <span class="string">&quot;Maven&quot;</span>, <span class="string">&quot;Amen&quot;</span>, <span class="string">&quot;eleven&quot;</span>&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> _, word := <span class="keyword">range</span> words &#123;</span><br><span class="line"></span><br><span class="line">		found, err := regexp.MatchString(<span class="string">&quot;.even&quot;</span>, word)</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			log.Fatal(err)</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span> found &#123;</span><br><span class="line"></span><br><span class="line">			fmt.Printf(<span class="string">&quot;%s matches\n&quot;</span>, word)</span><br><span class="line">		&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">			fmt.Printf(<span class="string">&quot;%s does not match\n&quot;</span>, word)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>运行该代码：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Seven <span class="keyword">matches</span></span><br><span class="line">even does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">Maven does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">Amen does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">eleven <span class="keyword">matches</span></span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>但同时我们能看到编辑器有提示，说明直接用 <code>MatchString</code> 匹配字符串会影响性能。：</p>
<p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fd46db2f624845bea349deb9d98b12cf~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.awebp" alt="image.png"></p>
<p>所以我们考虑用 <code>Compile()</code> 或者 <code>MustCompile()</code>创建一个编译好的正则表达式对象，然后再来进行模式匹配。</p>
<h2 id="Compile-函数"><a href="#Compile-函数" class="headerlink" title="Compile 函数"></a>Compile 函数</h2><p><code>Compile</code> 函数解析正则表达式，如果成功，则返回可用于匹配文本的 Regexp 对象。编译的正则表达式产生更快的代码。假如正则表达式非法，那么 <code>Compile()</code> 方法回返回 error ,而 <code>MustCompile()</code> 编译非法正则表达式时不会返回 error ，而是返回 panic 。</p>
<p>先来看 <code>Compile</code> 函数：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;log&quot;</span></span><br><span class="line">	<span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">	words := [...]<span class="type">string</span>&#123;<span class="string">&quot;Seven&quot;</span>, <span class="string">&quot;even&quot;</span>, <span class="string">&quot;Maven&quot;</span>, <span class="string">&quot;Amen&quot;</span>, <span class="string">&quot;eleven&quot;</span>&#125;</span><br><span class="line"></span><br><span class="line">	re, err := regexp.Compile(<span class="string">&quot;.even&quot;</span>)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		log.Fatal(err)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> _, word := <span class="keyword">range</span> words &#123;</span><br><span class="line"></span><br><span class="line">		found := re.MatchString(word)</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span> found &#123;</span><br><span class="line"></span><br><span class="line">			fmt.Printf(<span class="string">&quot;%s matches\n&quot;</span>, word)</span><br><span class="line">		&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">			fmt.Printf(<span class="string">&quot;%s does not match\n&quot;</span>, word)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>在代码示例中，我们使用了编译的正则表达式。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">re, err := regexp.Compile(<span class="string">&quot;.even&quot;</span>)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>即使用 <code>Compile</code> 编译正则表达式。然后在返回的正则表达式对象上调用 <code>MatchString</code> 函数：</p>
<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">found := re.<span class="built_in">MatchString</span>(<span class="type">word</span>)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>运行程序，能看到同样的代码：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Seven <span class="keyword">matches</span></span><br><span class="line">even does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">Maven does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">Amen does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">eleven <span class="keyword">matches</span></span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h2 id="MustCompile-函数"><a href="#MustCompile-函数" class="headerlink" title="MustCompile 函数"></a>MustCompile 函数</h2><p>再看使用 <code>MustCompile</code> 函数的例子，它编译正则表达式并在无法解析表达式时发生 panic。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">	words := [...]<span class="type">string</span>&#123;<span class="string">&quot;Seven&quot;</span>, <span class="string">&quot;even&quot;</span>, <span class="string">&quot;Maven&quot;</span>, <span class="string">&quot;Amen&quot;</span>, <span class="string">&quot;eleven&quot;</span>&#125;</span><br><span class="line"></span><br><span class="line">	re := regexp.MustCompile(<span class="string">&quot;.even&quot;</span>)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> _, word := <span class="keyword">range</span> words &#123;</span><br><span class="line"></span><br><span class="line">		found := re.MatchString(word)</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span> found &#123;</span><br><span class="line"></span><br><span class="line">			fmt.Printf(<span class="string">&quot;%s matches\n&quot;</span>, word)</span><br><span class="line">		&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">			fmt.Printf(<span class="string">&quot;%s does not match\n&quot;</span>, word)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>运行该代码:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ go run main.go </span><br><span class="line">Seven <span class="keyword">matches</span></span><br><span class="line">even does <span class="keyword">not</span> <span class="keyword">match</span> </span><br><span class="line">Maven does <span class="keyword">not</span> <span class="keyword">match</span></span><br><span class="line">Amen does <span class="keyword">not</span> <span class="keyword">match</span> </span><br><span class="line">eleven <span class="keyword">matches</span> </span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h2 id="FindString-查找字符串"><a href="#FindString-查找字符串" class="headerlink" title="FindString 查找字符串"></a>FindString 查找字符串</h2><p><code>FindString()</code> 用来返回第一个匹配的结果。如果没有匹配的字符串，那么它回返回一个空的字符串，当然如果你的正则表达式就是要匹配空字符串的话，它也会返回空字符串。使用 <code>FindStringIndex</code> 或者 <code>FindStringSubmatch</code>可以区分这两种情况。下面是<code>FindString()</code>的例子：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">	str := <span class="string">&quot;Today is Tuesday!&quot;</span></span><br><span class="line"></span><br><span class="line">	regexp, _ := regexp.Compile(<span class="string">&quot;^T([a-z]+)y&quot;</span>)</span><br><span class="line"></span><br><span class="line">	fmt.Println(regexp.FindString(str))</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>运行该代码，可以看到如下结果：</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="keyword">go</span> run main.<span class="keyword">go</span> </span><br><span class="line">Today</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h2 id="FindAllString-函数"><a href="#FindAllString-函数" class="headerlink" title="FindAllString 函数"></a>FindAllString 函数</h2><p><code>FindAllString</code> 函数返回正则表达式的所有连续匹配的切片。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;os&quot;</span></span><br><span class="line">    <span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> content = <span class="string">`Foxes are omnivorous mammals belonging to several genera </span></span><br><span class="line"><span class="string">of the family Canidae. Foxes have a flattened skull, upright triangular ears, </span></span><br><span class="line"><span class="string">a pointed, slightly upturned snout, and a long bushy tail. Foxes live on every </span></span><br><span class="line"><span class="string">continent except Antarctica. By far the most common and widespread species of </span></span><br><span class="line"><span class="string">fox is the red fox.`</span></span><br><span class="line"></span><br><span class="line">    re := regexp.MustCompile(<span class="string">&quot;(?i)fox(es)?&quot;</span>)</span><br><span class="line"></span><br><span class="line">    found := re.FindAllString(content, <span class="number">-1</span>)</span><br><span class="line"></span><br><span class="line">    fmt.Printf(<span class="string">&quot;%q\n&quot;</span>, found)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> found == <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Printf(<span class="string">&quot;no match found\n&quot;</span>)</span><br><span class="line">        os.Exit(<span class="number">1</span>)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> _, word := <span class="keyword">range</span> found &#123;</span><br><span class="line">        fmt.Printf(<span class="string">&quot;%s\n&quot;</span>, word)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>在代码示例中，我们找到了单词 fox 的所有出现，包括它的复数形式。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">re := regexp.<span class="built_in">MustCompile</span>(<span class="string">&quot;(?i)fox(es)?&quot;</span>)</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>使用 (?i) 语法，正则表达式不区分大小写。 （es）？表示“es”字符可能包含零次或一次。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">found := re.<span class="built_in">FindAllString</span>(content, -<span class="number">1</span>)</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>我们使用 <code>FindAllString</code> 查找所有出现的已定义正则表达式。第二个参数是要查找的最大匹配项； -1 表示搜索所有可能的匹配项。</p>
<p>运行结果：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-attr">[<span class="string">&quot;Foxes&quot;</span> <span class="string">&quot;Foxes&quot;</span> <span class="string">&quot;Foxes&quot;</span> <span class="string">&quot;fox&quot;</span> <span class="string">&quot;fox&quot;</span>]</span></span><br><span class="line">Foxes</span><br><span class="line">Foxes</span><br><span class="line">Foxes</span><br><span class="line">fox</span><br><span class="line">fox</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="FindAllStringIndex-函数"><a href="#FindAllStringIndex-函数" class="headerlink" title="FindAllStringIndex 函数"></a>FindAllStringIndex 函数</h2><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> content = <span class="string">`Foxes are omnivorous mammals belonging to several genera </span></span><br><span class="line"><span class="string">of the family Canidae. Foxes have a flattened skull, upright triangular ears, </span></span><br><span class="line"><span class="string">a pointed, slightly upturned snout, and a long bushy tail. Foxes live on every </span></span><br><span class="line"><span class="string">continent except Antarctica. By far the most common and widespread species of </span></span><br><span class="line"><span class="string">fox is the red fox.`</span></span><br><span class="line"></span><br><span class="line">    re := regexp.MustCompile(<span class="string">&quot;(?i)fox(es)?&quot;</span>)</span><br><span class="line"></span><br><span class="line">    idx := re.FindAllStringIndex(content, <span class="number">-1</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> _, j := <span class="keyword">range</span> idx &#123;</span><br><span class="line">        match := content[j[<span class="number">0</span>]:j[<span class="number">1</span>]]</span><br><span class="line">        fmt.Printf(<span class="string">&quot;%s at %d:%d\n&quot;</span>, match, j[<span class="number">0</span>], j[<span class="number">1</span>])</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>在代码示例中，我们在文本中找到所有出现的 fox 单词及其索引。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Foxes at 0:5</span><br><span class="line">Foxes at 81:86</span><br><span class="line">Foxes at 196:201</span><br><span class="line">fox at 296:299</span><br><span class="line">fox at 311:314</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h2 id="Split-函数"><a href="#Split-函数" class="headerlink" title="Split 函数"></a>Split 函数</h2><p><code>Split</code> 函数将字符串切割成由定义的正则表达式分隔的子字符串。它返回这些表达式匹配之间的子字符串切片。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;log&quot;</span></span><br><span class="line">    <span class="string">&quot;regexp&quot;</span></span><br><span class="line">    <span class="string">&quot;strconv&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> data = <span class="string">`22, 1, 3, 4, 5, 17, 4, 3, 21, 4, 5, 1, 48, 9, 42`</span></span><br><span class="line"></span><br><span class="line">    sum := <span class="number">0</span></span><br><span class="line"></span><br><span class="line">    re := regexp.MustCompile(<span class="string">&quot;,\s*&quot;</span>)</span><br><span class="line"></span><br><span class="line">    vals := re.Split(data, <span class="number">-1</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> _, val := <span class="keyword">range</span> vals &#123;</span><br><span class="line"></span><br><span class="line">        n, err := strconv.Atoi(val)</span><br><span class="line"></span><br><span class="line">        sum += n</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">            log.Fatal(err)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    fmt.Println(sum)</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>在代码示例中，我们有一个逗号分隔的值列表。我们从字符串中截取值并计算它们的总和。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">re := regexp.MustCompile(<span class="string">&quot;,\s*&quot;</span>)</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>正则表达式包括一个逗号字符和任意数量的相邻空格。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vals := re.Split(data, <span class="number">-1</span>)</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>我们得到了值的一部分。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> _, val := <span class="keyword">range</span> vals &#123;</span><br><span class="line"></span><br><span class="line">    n, err := strconv.Atoi(val)</span><br><span class="line"></span><br><span class="line">    sum += n</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        log.Fatal(err)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>我们遍历切片并计算总和。切片包含字符串；因此，我们使用 <code>strconv.Atoi</code> 函数将每个字符串转换为整数。</p>
<p>运行代码：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">189</span><br><span class="line">复制代码</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="Go-正则表达式捕获组"><a href="#Go-正则表达式捕获组" class="headerlink" title="Go 正则表达式捕获组"></a>Go 正则表达式捕获组</h2><p>圆括号 () 用于创建捕获组。这允许我们将量词应用于整个组或将交替限制为正则表达式的一部分。 为了找到捕获组（Go 使用术语子表达式），我们使用 <code>FindStringSubmatch</code> 函数。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;regexp&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    websites := [...]<span class="type">string</span>&#123;<span class="string">&quot;webcode.me&quot;</span>, <span class="string">&quot;zetcode.com&quot;</span>, <span class="string">&quot;freebsd.org&quot;</span>, <span class="string">&quot;netbsd.org&quot;</span>&#125;</span><br><span class="line"></span><br><span class="line">    re := regexp.MustCompile(<span class="string">&quot;(\w+)\.(\w+)&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> _, website := <span class="keyword">range</span> websites &#123;</span><br><span class="line"></span><br><span class="line">        parts := re.FindStringSubmatch(website)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> i, _ := <span class="keyword">range</span> parts &#123;</span><br><span class="line">            fmt.Println(parts[i])</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        fmt.Println(<span class="string">&quot;---------------------&quot;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>在代码示例中，我们使用组将域名分为两部分。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">re := regexp.MustCompile(<span class="string">&quot;(\w+)\.(\w+)&quot;</span>)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>我们用括号定义了两个组。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">parts := re.FindStringSubmatch(website)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p><code>FindStringSubmatch</code> 返回包含匹配项的字符串切片，包括来自捕获组的字符串。</p>
<p>运行代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">$ go run capturegroups.go </span><br><span class="line">webcode.me</span><br><span class="line">webcode</span><br><span class="line">me</span><br><span class="line">---------------------</span><br><span class="line">zetcode.com</span><br><span class="line">zetcode</span><br><span class="line">com</span><br><span class="line">---------------------</span><br><span class="line">freebsd.org</span><br><span class="line">freebsd</span><br><span class="line">org</span><br><span class="line">---------------------</span><br><span class="line">netbsd.org</span><br><span class="line">netbsd</span><br><span class="line">org</span><br><span class="line">---------------------</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h2 id="正则表达式替换字符串"><a href="#正则表达式替换字符串" class="headerlink" title="正则表达式替换字符串"></a>正则表达式替换字符串</h2><p>可以用 <code>ReplaceAllString</code> 替换字符串。该方法返回修改后的字符串。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;io/ioutil&quot;</span></span><br><span class="line">    <span class="string">&quot;log&quot;</span></span><br><span class="line">    <span class="string">&quot;net/http&quot;</span></span><br><span class="line">    <span class="string">&quot;regexp&quot;</span></span><br><span class="line">    <span class="string">&quot;strings&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    resp, err := http.Get(<span class="string">&quot;http://webcode.me&quot;</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        log.Fatal(err)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">defer</span> resp.Body.Close()</span><br><span class="line"></span><br><span class="line">    body, err := ioutil.ReadAll(resp.Body)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line"></span><br><span class="line">        log.Fatal(err)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    content := <span class="type">string</span>(body)</span><br><span class="line"></span><br><span class="line">    re := regexp.MustCompile(<span class="string">&quot;&lt;[^&gt;]*&gt;&quot;</span>)</span><br><span class="line">    replaced := re.ReplaceAllString(content, <span class="string">&quot;&quot;</span>)</span><br><span class="line"></span><br><span class="line">    fmt.Println(strings.TrimSpace(replaced))</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>该示例读取网页的 HTML 数据并使用正则表达式去除其 HTML 标记。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">resp, err := http.<span class="built_in">Get</span>(<span class="string">&quot;http://webcode.me&quot;</span>)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>我们使用 http 包中的 Get 函数创建一个 GET 请求。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">body</span>, err := ioutil.<span class="built_in">ReadAll</span>(resp.Body)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>我们读取响应对象的主体。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">re := regexp.<span class="built_in">MustCompile</span>(<span class="string">&quot;&lt;[^&gt;]*&gt;&quot;</span>)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>这个模式定义了一个匹配 HTML 标签的正则表达式。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">replaced := re.<span class="built_in">ReplaceAllString</span>(content, <span class="string">&quot;&quot;</span>)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>我们使用 ReplaceAllString 方法删除所有标签。</p>
<h2 id="ReplaceAllStringFunc-函数"><a href="#ReplaceAllStringFunc-函数" class="headerlink" title="ReplaceAllStringFunc 函数"></a>ReplaceAllStringFunc 函数</h2><p><code>ReplaceAllStringFunc</code> 返回一个字符串的副本，其中正则表达式的所有匹配项都已替换为指定函数的返回值。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span></span><br><span class="line">    <span class="string">&quot;regexp&quot;</span></span><br><span class="line">    <span class="string">&quot;strings&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    content := <span class="string">&quot;an old eagle&quot;</span></span><br><span class="line"></span><br><span class="line">    re := regexp.MustCompile(<span class="string">`[^aeiou]`</span>)</span><br><span class="line"></span><br><span class="line">    fmt.Println(re.ReplaceAllStringFunc(content, strings.ToUpper))</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>在代码示例中，我们将 <code>strings.ToUpper</code> 函数应用于字符串的所有字符。</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="keyword">go</span> run replaceallfunc.<span class="keyword">go</span> </span><br><span class="line">aN oLD eaGLe</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>模式匹配在根据基于正则表达式和语法的特定搜索模式在字符串中搜索某些字符集时起着重要作用。匹配的模式允许我们从字符串中提取所需的数据并以我们喜欢的方式对其进行操作。理解和使用正则表达式是处理文本的关键。</p>
<p>在实际过程中，程序员会保留一组常用的正则表达式来匹配电子邮件、电话号码等，并在需要时使用和重用它。</p>
<p>本文只是简单挑选了一些常见的函数进行介绍，其实 <code>regexp</code> 包还有更多的函数，留给读者自己去探索和研究。</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/golang/" rel="tag">golang</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/javascript/" rel="tag">javascript</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" rel="tag">正则表达式</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-入门-PythonJsBootStrapCSS之路"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/09/%E5%85%A5%E9%97%A8-PythonJsBootStrapCSS%E4%B9%8B%E8%B7%AF/"
    >人生苦短,我用Python</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/09/%E5%85%A5%E9%97%A8-PythonJsBootStrapCSS%E4%B9%8B%E8%B7%AF/" class="article-date">
  <time datetime="2023-05-09T13:53:08.000Z" itemprop="datePublished">2023-05-09</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Python/">Python</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="Python核心基础"><a href="#Python核心基础" class="headerlink" title="Python核心基础"></a>Python核心基础</h1><h2 id="Print"><a href="#Print" class="headerlink" title="Print"></a>Print</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#不换行</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;aabbcc&quot;</span>.title(),end=<span class="string">&quot; &quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">#编码</span></span><br><span class="line">s = <span class="string">&quot;中国&quot;</span></span><br><span class="line">code1 = s.encode(<span class="string">&#x27;utf-8&#x27;</span>);</span><br><span class="line">code2 = s.encode(<span class="string">&#x27;gbk&#x27;</span>);</span><br><span class="line"><span class="built_in">print</span>(code1,code2);</span><br><span class="line"></span><br><span class="line"><span class="comment">#解码</span></span><br><span class="line">s1 = code1.decode(<span class="string">&#x27;utf-8&#x27;</span>);</span><br><span class="line">s2 = code2.decode(<span class="string">&#x27;gbk&#x27;</span>);</span><br></pre></td></tr></table></figure>

<h2 id="format"><a href="#format" class="headerlink" title="format"></a>format</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">v1 = <span class="string">&quot;我在&#123;&#125;，今年&#123;&#125;岁&quot;</span>.<span class="built_in">format</span>(<span class="string">&quot;湖北&quot;</span>,<span class="number">90</span>);</span><br><span class="line">a = <span class="string">&quot;湖北&quot;</span>;</span><br><span class="line">b = <span class="number">90</span>;</span><br><span class="line">v1 = <span class="string">f&quot;我是<span class="subst">&#123;a&#125;</span>,今年<span class="subst">&#123;b&#125;</span>岁&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 程序时间暂停10秒执行：</span></span><br><span class="line">t1=time.strftime(<span class="string">&#x27;%Y-%m-%d %H:%M:%S&#x27;</span>, time.localtime())</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;暂停开始：&#123;&#125;&quot;</span>.<span class="built_in">format</span>(t1))</span><br><span class="line">time.sleep( <span class="number">10</span> )</span><br><span class="line">t2=time.strftime(<span class="string">&#x27;%Y-%m-%d %H:%M:%S&#x27;</span>, time.localtime())</span><br><span class="line"><span class="built_in">print</span>(<span class="string">&quot;暂停结束：&#123;&#125;&quot;</span>.<span class="built_in">format</span>(t2))</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="If"><a href="#If" class="headerlink" title="If"></a>If</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> condition:</span><br><span class="line">    do something</span><br><span class="line"><span class="keyword">elif</span> condition:</span><br><span class="line">    do something</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    do something</span><br></pre></td></tr></table></figure>

<h2 id="List"><a href="#List" class="headerlink" title="List"></a>List</h2><table>
<thead>
<tr>
<th>方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>L.append(object)</td>
<td>追加</td>
</tr>
<tr>
<td>L.clear()</td>
<td>清空</td>
</tr>
<tr>
<td>L.count(value)</td>
<td>计算value在列表中出现的次数</td>
</tr>
<tr>
<td>L.copy()</td>
<td>返回L备份的新对象</td>
</tr>
<tr>
<td>L.extend(Lb)</td>
<td>将Lb的项扩充到L中</td>
</tr>
<tr>
<td>L.index(value,[start,[stop]])</td>
<td>计算value在列表L指定区间第一次出现的索引值</td>
</tr>
<tr>
<td>L.insert(index,object)</td>
<td>定位插入</td>
</tr>
<tr>
<td>L.pop([index])</td>
<td>返回并移除项，默认最后一个</td>
</tr>
<tr>
<td>L.remove(value)</td>
<td>移除第一个值为value的项</td>
</tr>
<tr>
<td>L.reverse()</td>
<td>倒置列表L</td>
</tr>
<tr>
<td>L.sort()</td>
<td>从低到高排序</td>
</tr>
<tr>
<td>L.sort(reverse&#x3D;True)</td>
<td>从高到低排序</td>
</tr>
</tbody></table>
<h2 id="Range"><a href="#Range" class="headerlink" title="Range"></a>Range</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">range</span>([start,]stop[,step])</span><br></pre></td></tr></table></figure>

<h2 id="For"><a href="#For" class="headerlink" title="For"></a>For</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> item <span class="keyword">in</span> interable:</span><br><span class="line">    do something</span><br><span class="line"></span><br><span class="line">或者</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(<span class="type">List</span>)):</span><br><span class="line">    do something</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="While"><a href="#While" class="headerlink" title="While"></a>While</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> condition:</span><br><span class="line">    do something</span><br></pre></td></tr></table></figure>

<h2 id="Input"><a href="#Input" class="headerlink" title="Input"></a>Input</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">message=<span class="string">&quot; &quot;</span></span><br><span class="line"><span class="keyword">while</span> message != <span class="string">&quot;quit&quot;</span>:</span><br><span class="line">    message = <span class="built_in">input</span>(<span class="string">&quot;输入你要显示的信息（输入&#x27;quit&#x27;退出）：&quot;</span>)</span><br><span class="line">    <span class="keyword">if</span> message != <span class="string">&quot;quit&quot;</span>:</span><br><span class="line">        <span class="built_in">print</span>(message)</span><br></pre></td></tr></table></figure>

<h2 id="Function"><a href="#Function" class="headerlink" title="Function"></a>Function</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">def &lt;函数名&gt; (参数列表):</span><br><span class="line">	&lt;函数语句&gt;</span><br><span class="line">	[return &lt;返回值&gt;]</span><br></pre></td></tr></table></figure>

<h2 id="Class-Object"><a href="#Class-Object" class="headerlink" title="Class-Object"></a>Class-Object</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Book</span>():</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self,name,pages</span>):</span><br><span class="line">        self.name=name</span><br><span class="line">        self.pages=pages</span><br><span class="line">        </span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">show</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="built_in">print</span>(self.name)</span><br><span class="line"></span><br><span class="line">b = Book(<span class="string">&quot;Python&quot;</span>,<span class="number">255</span>)</span><br><span class="line">b.show()</span><br></pre></td></tr></table></figure>

<h2 id="Module"><a href="#Module" class="headerlink" title="Module"></a>Module</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> 模块名</span><br><span class="line"><span class="keyword">import</span> 模块名 <span class="keyword">as</span> 新名字</span><br><span class="line"><span class="keyword">from</span>   模块名 <span class="keyword">import</span> 函数名</span><br><span class="line"></span><br><span class="line"><span class="built_in">dir</span>()              <span class="comment">#查看模块内的：函数名称/类名称/常量名称</span></span><br><span class="line"><span class="built_in">help</span>(time.asctime) <span class="comment">#查看函数的使用帮助</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="常见的模块"><a href="#常见的模块" class="headerlink" title="常见的模块"></a>常见的模块</h3><h4 id="os模块"><a href="#os模块" class="headerlink" title="os模块"></a>os模块</h4><table>
<thead>
<tr>
<th>名称</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>os.getcwd()</td>
<td>返回当前工作目录</td>
</tr>
<tr>
<td>os.chdir(path)</td>
<td>改变工作目录</td>
</tr>
<tr>
<td>os.listdir(path&#x3D;”.”)</td>
<td>列举指定目录中的文件名</td>
</tr>
<tr>
<td>os.mkdir(path)</td>
<td>创建目录</td>
</tr>
<tr>
<td>os.makedirs(path)</td>
<td>创建级联目录</td>
</tr>
<tr>
<td>os.remove(path)</td>
<td>删除文件</td>
</tr>
<tr>
<td>os.rmdir(path)</td>
<td>删除目录</td>
</tr>
<tr>
<td>os.removedirs(path)</td>
<td>递归删除目录</td>
</tr>
<tr>
<td>os.rename(old,new)</td>
<td>改名</td>
</tr>
<tr>
<td>os.system()</td>
<td>运行Shell命令</td>
</tr>
</tbody></table>
<h4 id="math模块"><a href="#math模块" class="headerlink" title="math模块"></a>math模块</h4><table>
<thead>
<tr>
<th>名称</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>math.e</td>
<td>自然常数e</td>
</tr>
<tr>
<td>math.pi</td>
<td>圆周率</td>
</tr>
<tr>
<td>math.ceil(x)</td>
<td>向上取整</td>
</tr>
<tr>
<td>math.floor(x)</td>
<td>向下取整</td>
</tr>
<tr>
<td>math.pow(x,y)</td>
<td>指数运算，得到x的y次方</td>
</tr>
<tr>
<td>math.log(x)</td>
<td>对数，默认基底为e</td>
</tr>
<tr>
<td>math.sin(x)</td>
<td>正弦函数</td>
</tr>
<tr>
<td>math.cos(x)</td>
<td>余弦函数</td>
</tr>
<tr>
<td>math.tan(x)</td>
<td>正切函数</td>
</tr>
<tr>
<td>math.degrees(x)</td>
<td>角度转换成弧度</td>
</tr>
<tr>
<td>math.radians(x)</td>
<td>弧度转换成角度</td>
</tr>
</tbody></table>
<h4 id="random模块"><a href="#random模块" class="headerlink" title="random模块"></a>random模块</h4><table>
<thead>
<tr>
<th>名称</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>random.random()</td>
<td>随机生成一个【0，1】范围内的实数</td>
</tr>
<tr>
<td>random.randint(a,b)</td>
<td>随机生成一个【a，b】范围内的整数</td>
</tr>
<tr>
<td>random.uniform(a,b)</td>
<td>随机生成一个【a，b】范围内的实数</td>
</tr>
<tr>
<td>random.choice(seq)</td>
<td>从序列中随机挑选一个元素</td>
</tr>
<tr>
<td>random.sample(seq,k)</td>
<td>从序列中随机挑选k个元素</td>
</tr>
<tr>
<td>random.shuffle(seq)</td>
<td>将序列的所有元素随机排序</td>
</tr>
</tbody></table>
<h4 id="Image模块"><a href="#Image模块" class="headerlink" title="Image模块"></a>Image模块</h4><table>
<thead>
<tr>
<th>名称</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>im&#x3D;Image.open(infile)</td>
<td>打开文件句柄</td>
</tr>
<tr>
<td>im.show()</td>
<td>显示图像</td>
</tr>
<tr>
<td>im.format</td>
<td>查看图像格式</td>
</tr>
<tr>
<td>im.size</td>
<td>查看图像（宽度，高度）</td>
</tr>
<tr>
<td>im.height</td>
<td>高度</td>
</tr>
<tr>
<td>im.width</td>
<td>宽度</td>
</tr>
<tr>
<td>im.save(infile)</td>
<td>保存图像</td>
</tr>
<tr>
<td>im.rotate(d)</td>
<td>旋转一定角度</td>
</tr>
<tr>
<td>im.resize((x,y))</td>
<td>图像缩放</td>
</tr>
</tbody></table>
<h4 id="PIL库在Image模块中"><a href="#PIL库在Image模块中" class="headerlink" title="PIL库在Image模块中"></a>PIL库在Image模块中</h4><p>​		PIL对图像的基本操作，如打开图像等。</p>
<h4 id="numpy模块"><a href="#numpy模块" class="headerlink" title="numpy模块"></a>numpy模块</h4><p>​		numpy的主要对象是同质多维数组，将图像的RGB值以矩阵形式存储。</p>
<h4 id="matplotlib模块"><a href="#matplotlib模块" class="headerlink" title="matplotlib模块"></a>matplotlib模块</h4><p>​		matplotlib是一个2D绘图库。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#彩色图片转黑白色示例代码：</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line">img = np.array(Image.<span class="built_in">open</span>(<span class="string">&#x27;aaa.jpg&#x27;</span>).convert(<span class="string">&#x27;L&#x27;</span>))  <span class="comment">#convert用于不同模式图像转换，&quot;L&quot; 为灰色图像</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 自定义修改像素值：</span></span><br><span class="line"><span class="comment"># num = 128</span></span><br><span class="line"><span class="comment"># rows,cols = img.shape           #图像尺寸分别赋值</span></span><br><span class="line"><span class="comment"># for i in range(rows):</span></span><br><span class="line"><span class="comment">#     for j in range(cols):</span></span><br><span class="line"><span class="comment">#         if(img[i,j] &gt; num):     #像素值大于128，赋值1，否则为2</span></span><br><span class="line"><span class="comment">#             img[i,j]=1</span></span><br><span class="line"><span class="comment">#         else:</span></span><br><span class="line"><span class="comment">#             img[i,j]=0</span></span><br><span class="line"></span><br><span class="line">plt.figure(<span class="string">&quot;new图片&quot;</span>)		    <span class="comment">#指定当前绘图对象</span></span><br><span class="line">plt.imshow(img,cmap=<span class="string">&#x27;gray&#x27;</span>)  <span class="comment">#显示灰度图像</span></span><br><span class="line">plt.axis(<span class="string">&#x27;off&#x27;</span>)              <span class="comment">#关闭图像坐标</span></span><br><span class="line">plt.show()                   <span class="comment">#弹出包含了图片的窗口</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<hr>
<h2 id="Python环境安装"><a href="#Python环境安装" class="headerlink" title="Python环境安装"></a>Python环境安装</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">下载： C:\Users\Lenovo\Downloads\python-3.10.10-amd64.exe</span><br><span class="line">双击安装，勾选PATH,默认安装路径：C:\Users\Lenovo\AppData\Local\Programs\Python\Python310</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="常见模块安装"><a href="#常见模块安装" class="headerlink" title="常见模块安装"></a>常见模块安装</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">安装相关模块</span></span><br><span class="line">pip3 install Pillow      #是Python图像处理的基础库</span><br><span class="line">pip3 install numpy       #主要对象是同质多维数组，将图像的RGB值以矩阵形式存储</span><br><span class="line">pip3 install matplotlib  #是一个2D绘图库</span><br><span class="line">pip3 install tkinter     #Python内置的GUI模块</span><br><span class="line"></span><br><span class="line">pip3 install JayDeBeApi  #发送ajax请求</span><br><span class="line">pip3 install markdown    #view视图中获取到数据库的数据，修饰为html语句，传到前端</span><br><span class="line">pip3 install Pygments    #实现代码高亮</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h4 id="报错处理：在python3里面无法找到PIL版本"><a href="#报错处理：在python3里面无法找到PIL版本" class="headerlink" title="报错处理：在python3里面无法找到PIL版本"></a>报错处理：在python3里面无法找到PIL版本</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">结果显示:</span><br><span class="line">提示——Could not find a version that satisfies the requirement PIL (from versions: )No matching distribution found for PIL</span><br><span class="line">错误原因：</span><br><span class="line">起初安装命令是按照 pip install PIL来安装的，现在已经用Pillow代替PIL，PIL较多用于2.7版本的Python中</span><br><span class="line">解决方案：</span><br><span class="line">pip install Pillow</span><br><span class="line">备注：</span><br><span class="line">1、升级pip，安装该第三方模板后，引入时也有原来的：import image变为：from PIL import Image</span><br><span class="line">2、安装python时要勾选pip和Add python.exe to Path</span><br><span class="line">3、第三方库查询： pypi.python.org</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="替换Python国内镜像源"><a href="#替换Python国内镜像源" class="headerlink" title="替换Python国内镜像源"></a>替换Python国内镜像源</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">豆瓣：http://pypi.douban.com/simple/</span><br><span class="line">中科大：https://pypi.mirrors.ustc.edu.cn/simple/</span><br><span class="line">清华：https://pypi.tuna.tsinghua.edu.cn/simple/</span><br><span class="line">阿里云：https://mirrors.aliyun.com/pypi/simple/</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">临时使用国内pypi镜像安装</span></span><br><span class="line">pip install PyQt6 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">永久替换，使用国内源库- 阿里</span></span><br><span class="line">pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">永久替换，使用国内源库- 清华</span></span><br><span class="line">pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h2 id="Module-2"><a href="#Module-2" class="headerlink" title="Module_2"></a>Module_2</h2><h3 id="turtle模块（海龟绘图）"><a href="#turtle模块（海龟绘图）" class="headerlink" title="turtle模块（海龟绘图）"></a>turtle模块（海龟绘图）</h3><table>
<thead>
<tr>
<th>函数</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>forward(x)    简写:fd(x)</td>
<td>前进，单位像素</td>
</tr>
<tr>
<td>backword(x)    简写:bk(x)</td>
<td>后退</td>
</tr>
<tr>
<td>goto(x,y)</td>
<td>当前点到x,y点化线</td>
</tr>
<tr>
<td>circle(r,extent&#x3D;None)</td>
<td>绘制半径为r，角度为extent的弧线。圆心默认在海龟上侧距离r的位置。当extent&#x3D;360时等价画圆circle(r) 。</td>
</tr>
<tr>
<td>left(x)    简写:lt(x)</td>
<td>左转角度</td>
</tr>
<tr>
<td>right(x)    简写:rt(x)</td>
<td>右转角度</td>
</tr>
<tr>
<td>down()</td>
<td>落笔</td>
</tr>
<tr>
<td>up()</td>
<td>抬笔</td>
</tr>
</tbody></table>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#画八角星</span></span><br><span class="line"><span class="keyword">import</span> turtle</span><br><span class="line">t = turtle.Pen()</span><br><span class="line">t.pencolor(<span class="string">&quot;red&quot;</span>)</span><br><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">9</span>):</span><br><span class="line">    t.fd(<span class="number">100</span>)</span><br><span class="line">    t.lt(<span class="number">225</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#画漂亮的圆</span></span><br><span class="line"><span class="keyword">import</span> turtle</span><br><span class="line">t = turtle.Pen()</span><br><span class="line">colors = [<span class="string">&quot;red&quot;</span>,<span class="string">&quot;green&quot;</span>,<span class="string">&#x27;blue&#x27;</span>,<span class="string">&quot;yellow&quot;</span>]</span><br><span class="line"><span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span> (<span class="number">1</span>,<span class="number">100</span>):</span><br><span class="line">    t.pencolor(colors[x%<span class="number">4</span>])</span><br><span class="line">    t.circle(x)</span><br><span class="line">    t.left(<span class="number">91</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="tkinter是Python内置的GUI模块"><a href="#tkinter是Python内置的GUI模块" class="headerlink" title="tkinter是Python内置的GUI模块"></a>tkinter是Python内置的GUI模块</h3><p>​	参考： <a target="_blank" rel="noopener" href="http://c.biancheng.net/tkinter/what-is-tkinter.html">http://c.biancheng.net/tkinter/what-is-tkinter.html</a></p>
<h4 id="主窗口："><a href="#主窗口：" class="headerlink" title="主窗口："></a>主窗口：</h4><table>
<thead>
<tr>
<th>属性</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>root &#x3D; tkinter.Tk()</td>
<td>生成主窗口</td>
</tr>
<tr>
<td>toot.title(‘标题名’)</td>
<td>框体名，也可以用className来命名。</td>
</tr>
<tr>
<td>root.resizable(0,0)</td>
<td>框体是否可变宽&#x2F;高</td>
</tr>
<tr>
<td>root.geometry(‘250 x 150’)</td>
<td>框体大小</td>
</tr>
<tr>
<td>root.quit()</td>
<td>退出</td>
</tr>
<tr>
<td>root.update()</td>
<td>刷新页面</td>
</tr>
<tr>
<td>root.mainloop()</td>
<td>进入消息循环（必须组件）</td>
</tr>
</tbody></table>
<h4 id="布局函数："><a href="#布局函数：" class="headerlink" title="布局函数："></a>布局函数：</h4><table>
<thead>
<tr>
<th>pack函数的参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>after</td>
<td>将组件置于其他组件之后</td>
</tr>
<tr>
<td>before</td>
<td>将组件置于其他组件之前</td>
</tr>
<tr>
<td>anchor</td>
<td>组件的对齐方式，顶n，底s，左w，右e</td>
</tr>
<tr>
<td>side</td>
<td>组件在主窗口的位置，top,bottom,left,right</td>
</tr>
<tr>
<td>fill</td>
<td>填充方式，垂直Y，水平X，水平加垂直BOTH</td>
</tr>
<tr>
<td>expand</td>
<td>0 or 1 ,是否随窗口缩放</td>
</tr>
</tbody></table>
<p>还有个表格布局：grid</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> tkinter <span class="keyword">as</span> tk</span><br><span class="line">root = tk.Tk()</span><br><span class="line">b1 = tk.Button(root, text=<span class="string">&#x27;b1&#x27;</span>)</span><br><span class="line">b2 = tk.Button(root, text=<span class="string">&#x27;b2&#x27;</span>)</span><br><span class="line">b1.grid(column=<span class="number">0</span>, row=<span class="number">0</span>)   <span class="comment"># grid dynamically divides the space in a grid</span></span><br><span class="line">b2.grid(column=<span class="number">1</span>, row=<span class="number">0</span>)   <span class="comment"># and arranges widgets accordingly</span></span><br><span class="line">root.mainloop()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="常见的组件："><a href="#常见的组件：" class="headerlink" title="常见的组件："></a>常见的组件：</h4><table>
<thead>
<tr>
<th>名称</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>Button</td>
<td>按钮</td>
</tr>
<tr>
<td>Canvas</td>
<td>绘制图形组件，可以在其中绘制图形</td>
</tr>
<tr>
<td>Checkbutton</td>
<td>复选框</td>
</tr>
<tr>
<td>Entry</td>
<td>文本框（单行）</td>
</tr>
<tr>
<td>Text</td>
<td>文本框（多行）</td>
</tr>
<tr>
<td>Frame</td>
<td>框架，将几个组件组成一组</td>
</tr>
<tr>
<td>Label</td>
<td>标签</td>
</tr>
<tr>
<td>Listbox</td>
<td>列表框</td>
</tr>
<tr>
<td>Menu</td>
<td>菜单</td>
</tr>
<tr>
<td>Menubutton</td>
<td>它的功能完全可以使用Menu替代</td>
</tr>
<tr>
<td>Message</td>
<td>与Label类似，但是可以根据自身大小将文本换行</td>
</tr>
<tr>
<td>Radiobutton</td>
<td>单选框</td>
</tr>
<tr>
<td>Scale</td>
<td>滑块，允许通过滑块来设置一数字值</td>
</tr>
<tr>
<td>Scrollbar</td>
<td>滚动条</td>
</tr>
<tr>
<td>Toplevel</td>
<td>用来创建子窗口的组件</td>
</tr>
</tbody></table>
<h4 id="Label标签组件："><a href="#Label标签组件：" class="headerlink" title="Label标签组件："></a>Label标签组件：</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line">root = Tk()</span><br><span class="line">label_1 = Label(root,text=<span class="string">&#x27;标签1&#x27;</span>)</span><br><span class="line">label_2 = Label(root,bitmap=<span class="string">&#x27;hourglass&#x27;</span>)</span><br><span class="line">label_1.pack()</span><br><span class="line">label_2.pack()</span><br><span class="line">root.mainloop()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>标题属性</th>
<th>标签值</th>
<th>标签属性</th>
<th>标签值</th>
</tr>
</thead>
<tbody><tr>
<td>Anchor 锚定</td>
<td>标签中文本的位置</td>
<td>background(bg) foreground(fg)</td>
<td>背景色 前景色</td>
</tr>
<tr>
<td>borderwidth</td>
<td>边框宽度</td>
<td>width,height</td>
<td>标签的大小</td>
</tr>
<tr>
<td>bitmap</td>
<td>标签中的位图</td>
<td>font</td>
<td>字体</td>
</tr>
<tr>
<td>image</td>
<td>标签中的图片</td>
<td>justify</td>
<td>多行文本对齐方式</td>
</tr>
<tr>
<td>text</td>
<td>标签中的文本</td>
<td>testvariable</td>
<td>显示文本自动更新，与StringVar等配合使用。</td>
</tr>
</tbody></table>
<p>python内置了10种位图：error,gray75,gray50,gray25,gray12,horglass,info,questhead,question,warning</p>
<h4 id="Button组件："><a href="#Button组件：" class="headerlink" title="Button组件："></a>Button组件：</h4><table>
<thead>
<tr>
<th>属性</th>
<th>取值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>text</td>
<td>字符串</td>
<td>按钮的文本</td>
</tr>
<tr>
<td>activebackground</td>
<td></td>
<td>当鼠标放上去时，按钮的背景颜色</td>
</tr>
<tr>
<td>activeforeground</td>
<td></td>
<td>当鼠标放上去时，按钮的前景颜色</td>
</tr>
<tr>
<td>bd(bordwidth)</td>
<td>默认为值为2个像素</td>
<td>按钮边框的大小</td>
</tr>
<tr>
<td>bg(background)</td>
<td></td>
<td>按钮的背景色</td>
</tr>
<tr>
<td>command</td>
<td>函数名的字符串形式</td>
<td>按钮关联的函数，当按钮点击时执行</td>
</tr>
<tr>
<td>fg(foreground)</td>
<td></td>
<td>按钮的的前景色</td>
</tr>
<tr>
<td>font</td>
<td></td>
<td>字体样式大小</td>
</tr>
<tr>
<td>image</td>
<td></td>
<td>按钮设置图片，必须是用图像函数create产生的</td>
</tr>
<tr>
<td>bitmap</td>
<td></td>
<td>指定按钮显示一张位图</td>
</tr>
<tr>
<td>state</td>
<td>DISABLED,ACTIVE,NORMAL</td>
<td>设置组件状态。禁用，激活，正常</td>
</tr>
<tr>
<td>width</td>
<td>单位像素</td>
<td>按钮的宽度，如未设置其大小自适应按钮的内容</td>
</tr>
<tr>
<td>height</td>
<td>单位像素</td>
<td>按钮的高度，同上</td>
</tr>
</tbody></table>
<h4 id="Entry组件："><a href="#Entry组件：" class="headerlink" title="Entry组件："></a>Entry组件：</h4><p>​	Entry是一个单行文本输入框。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line">root = Tk()</span><br><span class="line">e = StringVar()</span><br><span class="line">entry = Entry(root,textvariable = e,show=<span class="string">&quot;*&quot;</span>)</span><br><span class="line">e.<span class="built_in">set</span>(<span class="string">&#x27;请输入......&#x27;</span>)</span><br><span class="line">entry.pack()</span><br><span class="line">root.mainloop()</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h4 id="来一个完整的窗口示例："><a href="#来一个完整的窗口示例：" class="headerlink" title="来一个完整的窗口示例："></a>来一个完整的窗口示例：</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> time <span class="keyword">import</span> strftime</span><br><span class="line"></span><br><span class="line">root = Tk()</span><br><span class="line">root.geometry(<span class="string">&#x27;500x350+300+300&#x27;</span>)</span><br><span class="line">root.iconbitmap(<span class="string">&#x27;wangwei.ico&#x27;</span>)</span><br><span class="line">root.title(<span class="string">&quot;第一个窗口示例&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置文本标签</span></span><br><span class="line">lb = Label(root, font=(<span class="string">&quot;微软雅黑&quot;</span>, <span class="number">50</span>, <span class="string">&quot;bold&quot;</span>), bg=<span class="string">&#x27;#87CEEB&#x27;</span>, fg=<span class="string">&quot;#B452CD&quot;</span>)</span><br><span class="line">lb.pack(anchor=<span class="string">&quot;center&quot;</span>, fill=<span class="string">&quot;both&quot;</span>, expand=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义一个mode标志</span></span><br><span class="line">mode = <span class="string">&#x27;time&#x27;</span></span><br><span class="line"><span class="comment"># 定义显示时间的函数</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">showtime</span>():</span><br><span class="line">    <span class="keyword">if</span> mode == <span class="string">&#x27;time&#x27;</span>:</span><br><span class="line">        <span class="comment">#时间格式化处理   </span></span><br><span class="line">        string = strftime(<span class="string">&quot;%H:%M:%S %p&quot;</span>)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        string = strftime(<span class="string">&quot;%Y-%m-%d&quot;</span>)</span><br><span class="line">    lb.config(text=string)</span><br><span class="line">    <span class="comment"># 每隔 1秒钟执行time函数</span></span><br><span class="line">    lb.after(<span class="number">1000</span>, showtime)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义鼠标处理事件，点击时间切换为日期样式显示</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">mouseClick</span>(<span class="params">event</span>):</span><br><span class="line">    <span class="keyword">global</span> mode</span><br><span class="line">    <span class="keyword">if</span> mode == <span class="string">&#x27;time&#x27;</span>:</span><br><span class="line">        <span class="comment"># 点击切换mode样式为日期样式</span></span><br><span class="line">        mode = <span class="string">&#x27;date&#x27;</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        mode = <span class="string">&#x27;time&#x27;</span></span><br><span class="line"></span><br><span class="line">lb.bind(<span class="string">&quot;&lt;Button&gt;&quot;</span>, mouseClick)</span><br><span class="line"><span class="comment"># 调用showtime()函数</span></span><br><span class="line">showtime()</span><br><span class="line"><span class="comment"># 显示窗口</span></span><br><span class="line">mainloop()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h1 id="我的Python容器"><a href="#我的Python容器" class="headerlink" title="我的Python容器"></a>我的Python容器</h1><h2 id="安装docker"><a href="#安装docker" class="headerlink" title="安装docker"></a>安装docker</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">apt install docker.io</span><br><span class="line"></span><br><span class="line">    科大镜像：https://docker.mirrors.ustc.edu.cn/</span><br><span class="line">    网易：https://hub-mirror.c.163.com/</span><br><span class="line">    阿里云：https://&lt;你的ID&gt;.mirror.aliyuncs.com/</span><br><span class="line">    七牛云加速器：https://reg-mirror.qiniu.com/</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">Ubuntu16.04+、Debian8+、CentOS7 镜像加速</span></span><br><span class="line">对于使用 systemd 的系统，请在 /etc/docker/daemon.json 中写入如下内容（如果文件不存在请新建该文件）：</span><br><span class="line">&#123;&quot;registry-mirrors&quot;:[&quot;https://hub-mirror.c.163.com/&quot;]&#125;</span><br><span class="line"></span><br><span class="line">之后重新启动服务：</span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo systemctl daemon-reload</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">sudo systemctl restart docker</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="创建python容器"><a href="#创建python容器" class="headerlink" title="创建python容器"></a>创建python容器</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">docker pull python:3.10.10</span><br><span class="line">docker images</span><br><span class="line"></span><br><span class="line">mkdir ~/pythonDir/dir01</span><br><span class="line">echo &quot;date &gt; start.log&quot; &gt; ~/pythonDir/dir01/start.sh</span><br><span class="line">chmod 755  ~/pythonDir/dir01/start.sh</span><br><span class="line"></span><br><span class="line">docker run -itd --name py01 -v ~/pythonDir/dir01:/root/dir01 -w /root/dir01 python:latest &quot;/bin/bash&quot; </span><br><span class="line">docker run -itd --name py02 -v ~/pythonDir/dir01:/root/dir01 -w /root/dir01 python:3.10.10 &quot;/bin/bash&quot; </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">进入容器</span></span><br><span class="line">docker exec -it py01 bash</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="给容器更换镜像源-安装net-tools"><a href="#给容器更换镜像源-安装net-tools" class="headerlink" title="给容器更换镜像源-安装net-tools"></a>给容器更换镜像源-安装net-tools</h2><p> cat &gt; &#x2F;etc&#x2F;apt&#x2F;sources.list </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释</span></span><br><span class="line">deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free non-free-firmware</span><br><span class="line">deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free non-free-firmware</span><br><span class="line">deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free non-free-firmware</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">deb https://security.debian.org/debian-security bullseye-security main contrib non-free non-free-firmware</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>apt-get clean</p>
<p>apt-get update</p>
<p>apt-get upgrade</p>
<p>apt install net-tools</p>
<p>apt install iputils-ping</p>
<p>apt install vim     </p>
<p>还需要安装中文字体。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">apt-get install locales</span><br><span class="line">dpkg-reconfigure locales</span><br><span class="line">apt-get install ttf-wqy-zenhei</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="安装Python模块"><a href="#安装Python模块" class="headerlink" title="安装Python模块"></a>安装Python模块</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">安装相关模块</span></span><br><span class="line">pip3 install Pillow</span><br><span class="line">pip3 install numpy</span><br><span class="line">pip3 install matplotlib</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">安装完成后，测试一下tkinter画图程序。</span></span><br><span class="line">root@15535637f6f8:~/dir01/a01tkinter# python a01.py </span><br><span class="line">Traceback (most recent call last):</span><br><span class="line">  File &quot;/root/dir01/a01tkinter/a01.py&quot;, line 4, in &lt;module&gt;</span><br><span class="line">    root = Tk()</span><br><span class="line">           ^^^^</span><br><span class="line">  File &quot;/usr/local/lib/python3.11/tkinter/__init__.py&quot;, line 2326, in __init__</span><br><span class="line">    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)</span><br><span class="line">              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span><br><span class="line">_tkinter.TclError: no display name and no $DISPLAY environment variable</span><br><span class="line">root@15535637f6f8:~/dir01/a01tkinter#</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">终端需要图形界面才能运行Tk</span></span><br><span class="line">export DISPLAY=1.1.1.1:0.0</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="让windows接收Linux的图形"><a href="#让windows接收Linux的图形" class="headerlink" title="让windows接收Linux的图形"></a>让windows接收Linux的图形</h2><ul>
<li><p>winddows下载安装xming并安装。地址链接：<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/1hNMXnZ7gPdxdDh8ibF2LaQ">https://pan.baidu.com/s/1hNMXnZ7gPdxdDh8ibF2LaQ</a><br>提取码：vbiw</p>
</li>
<li><p>安装默认目录： C:\Program Files (x86)\Xming</p>
</li>
<li><p>启动Xming，可以看到Xmain在监听windows的:0.0</p>
</li>
<li><p>客户端设置环境变量：  export DISPLAY&#x3D;1.1.1.1:0.0</p>
</li>
<li><p>修改安装目录下的X0.hosts文件内容，添加你的客户端IP地址。重启Xmain。</p>
</li>
<li><p>客户端测试：xclock命令，时钟会出现在windows上。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">xwing中文乱码处理</span></span><br><span class="line">打开xlanch，一路下一步添加启动参数</span><br><span class="line">-fp &quot;C:/Windows/Fonts&quot;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">上面这样好像不行，我直接按照下面的方法启动xming</span></span><br><span class="line">Xming -fp &quot;C:/Program Files/Xming/fonts/misc/,C:/Program Files/Xming/fonts/TTF/,C:/Program Files/Xming/fonts/100dpi/,C:/Program Files/Xming/fonts/75dpi/,C:/Windows/Fonts&quot; -multiwindow -clipboard</span><br><span class="line"></span><br><span class="line">Xming.exe -fp &quot;C:/Windows/Fonts&quot; -multiwindow -clipboard</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="我的Python虚拟机"><a href="#我的Python虚拟机" class="headerlink" title="我的Python虚拟机"></a>我的Python虚拟机</h1><h3 id="下载安装python3-10-10"><a href="#下载安装python3-10-10" class="headerlink" title="下载安装python3.10.10"></a>下载安装python3.10.10</h3><ol>
<li><p>安装虚拟机 centos7.8 - 1.1.1.7 wei07 </p>
</li>
<li><p>安装 yum install gcc zlib</p>
</li>
<li><p>安装Python的底层依赖包： yum install  python3-tk   tk-devel  libffi-devel  (参考<a target="_blank" rel="noopener" href="https://blog.csdn.net/blueheart20/article/details/78763208">https://blog.csdn.net/blueheart20/article/details/78763208</a>)</p>
</li>
<li><p>yum -y install zlib-devel bzip2-devel openssl-devel  ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel  libpcap-devel xz-devel </p>
</li>
<li><p>解压pythong3.10.10.tgz</p>
</li>
<li><p>cd &#x2F;opt&#x2F;soft&#x2F;python&#x2F;Python-3.10.10 ;  </p>
<p>.&#x2F;configure  –prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;tools&#x2F;Python-3.10.10  –enable-shared </p>
<p>#注明：centos7不用加–enable-dhared，Ubuntu需要加。</p>
</li>
<li><p>make &amp;&amp; make install</p>
</li>
<li><pre><code class="text">export PYTHON_HOME=/usr/local/tools/Python-3.10.10
export PATH=$PYTHON_HOME/bin:$PATH

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">9. 修改pip3的国内源：</span><br><span class="line"></span><br><span class="line">   pip3 config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple</span><br><span class="line">   pip3 config set global.trusted-host mirrors.cloud.tencent.com</span><br><span class="line"></span><br><span class="line">10. 修改OS的Lib库环境变量：</span><br><span class="line"></span><br><span class="line">   ```shell</span><br><span class="line">   #添加一行： vim /etc/ld.so.conf</span><br><span class="line">   /usr/local/lib</span><br><span class="line">   </span><br><span class="line">   # 使配置生效</span><br><span class="line">   /sbin/ldconfig -v</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</code></pre>
</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">如果要有虚拟环境，步骤如下：</span></span><br><span class="line">pip install virtualenv</span><br><span class="line">virtualenv venv01 --python=python3</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h1 id="Python程序打包发布"><a href="#Python程序打包发布" class="headerlink" title="Python程序打包发布"></a>Python程序打包发布</h1><h3 id="安装-PyInstalle"><a href="#安装-PyInstalle" class="headerlink" title="安装 PyInstalle"></a>安装 PyInstalle</h3><p>​		 pip3 install pyinstaller</p>
<h3 id="PyInstaller生成可执行程序"><a href="#PyInstaller生成可执行程序" class="headerlink" title="PyInstaller生成可执行程序"></a>PyInstaller生成可执行程序</h3><p>​		<strong>用这个命令打包吧：pyinstaller -F 我的代码文件.py -n 打包后的程序名</strong></p>
<p> PyInstaller 工具的命令语法如下：</p>
<p> pyinstaller 选项 Python 源文件</p>
<p> 不管这个 Python 应用是单文件的应用，还是多文件的应用，只要在使用 pyinstaller 命令时编译作为程序入口的 Python 程序即可。</p>
<p> pyinstaller -F app.py</p>
<p> 执行上面命令，将看到详细的生成过程。当生成完成后，将会在此 app 目录下看到多了一个 dist 目录，并在该目录下看到有一个 app.exe 文件，这就是使用 PyInstaller 工具生成的 EXE 程序。</p>
<p> pyinstaller -D app.py</p>
<p> 执行上面命令，将看到详细的生成过程。当生成完成后，将会在 app 目录下看到多了一个 dist 目录，并在该目录下看到有一个 app  子目录，在该子目录下包含了大量 .dll 文件和 .pyz 文件，它们都是 app.exe 程序的支撑文件。在命令行窗口中运行该 app.exe 程序，同样可以看到与前一个 app.exe 程序相同的输出结果。</p>
<table>
<thead>
<tr>
<th>-h，–help</th>
<th>查看该模块的帮助信息</th>
</tr>
</thead>
<tbody><tr>
<td>-F，-onefile</td>
<td>产生单个的可执行文件</td>
</tr>
<tr>
<td>-D，–onedir</td>
<td>产生一个目录（包含多个文件）作为可执行程序</td>
</tr>
<tr>
<td>-a，–ascii</td>
<td>不包含 Unicode 字符集支持</td>
</tr>
<tr>
<td>-d，–debug</td>
<td>产生 debug 版本的可执行文件</td>
</tr>
<tr>
<td>-w，–windowed，–noconsolc</td>
<td>指定程序运行时不显示命令行窗口（仅对 Windows 有效）</td>
</tr>
<tr>
<td>-c，–nowindowed，–console</td>
<td>指定使用命令行窗口运行程序（仅对 Windows 有效）</td>
</tr>
<tr>
<td>-o DIR，–out&#x3D;DIR</td>
<td>指定 spec 文件的生成目录。如果没有指定，则默认使用当前目录来生成 spec 文件</td>
</tr>
<tr>
<td>-p DIR，–path&#x3D;DIR</td>
<td>设置 Python 导入模块的路径（和设置 PYTHONPATH 环境变量的作用相似）。也可使用路径分隔符（Windows 使用分号，Linux 使用冒号:）来分隔多个路径</td>
</tr>
<tr>
<td>-n NAME，–name&#x3D;NAME</td>
<td>指定项目（产生的 spec）名字。如果省略该选项，那么第一个脚本的主文件名将作为 spec 的名字</td>
</tr>
</tbody></table>
<p> 在表 1 中列出的只是 PyInstaller 模块所支持的常用选项，如果需要了解 PyInstaller 选项的详细信息，则可通过 pyinstaller -h 来查看。</p>
<p> 下面再创建一个带图形用户界面，可以访问  数据库的应用程序。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 导入访问MySQL的模块</span></span><br><span class="line"><span class="keyword">import</span> mysql.connector</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">query_db</span>():</span><br><span class="line">    <span class="comment"># ①、连接数据库</span></span><br><span class="line">    conn = conn = mysql.connector.connect(user=<span class="string">&#x27;root&#x27;</span>, password=<span class="string">&#x27;32147&#x27;</span>,</span><br><span class="line">        host=<span class="string">&#x27;localhost&#x27;</span>, port=<span class="string">&#x27;3306&#x27;</span>,</span><br><span class="line">        database=<span class="string">&#x27;python&#x27;</span>, use_unicode=<span class="literal">True</span>)</span><br><span class="line">    <span class="comment"># ②、获取游标</span></span><br><span class="line">    c = conn.cursor()</span><br><span class="line">    <span class="comment"># ③、调用执行select语句查询数据</span></span><br><span class="line">    c.execute(<span class="string">&#x27;select * from user_tb where user_id &gt; %s&#x27;</span>, (<span class="number">2</span>,))</span><br><span class="line">    <span class="comment"># 通过游标的description属性获取列信息</span></span><br><span class="line">    description = c.description</span><br><span class="line">    <span class="comment"># 使用fetchall获取游标中的所有结果集</span></span><br><span class="line">    rows = c.fetchall()</span><br><span class="line">    <span class="comment"># ④、关闭游标</span></span><br><span class="line">    c.close()</span><br><span class="line">    <span class="comment"># ⑤、关闭连接</span></span><br><span class="line">    conn.close()</span><br><span class="line">    <span class="keyword">return</span> description, rows</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> mian.py 文件包含的代码如下： </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> exec_select <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">main</span>():</span><br><span class="line">    description, rows = query_db()</span><br><span class="line">    <span class="comment"># 创建窗口</span></span><br><span class="line">    win = Tk()</span><br><span class="line">    win.title(<span class="string">&#x27;数据库查询&#x27;</span>)</span><br><span class="line">    <span class="comment"># 通过description获取列信息</span></span><br><span class="line">    <span class="keyword">for</span> i, col <span class="keyword">in</span> <span class="built_in">enumerate</span>(description):</span><br><span class="line">        lb = Button(win, text=col[<span class="number">0</span>], padx=<span class="number">50</span>, pady=<span class="number">6</span>)</span><br><span class="line">        lb.grid(row=<span class="number">0</span>, column=i)</span><br><span class="line">    <span class="comment"># 直接使用for循环查询得到的结果集</span></span><br><span class="line">    <span class="keyword">for</span> i, row <span class="keyword">in</span> <span class="built_in">enumerate</span>(rows):</span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(row)):</span><br><span class="line">            en = Label(win, text=row[j])</span><br><span class="line">            en.grid(row=i+<span class="number">1</span>, column=j)</span><br><span class="line">    win.mainloop()</span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    main()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p> 通过命令行工具进入 dbapp 目录下，在该目录下执行如下命令： </p>
<p> Pyinstaller -F -w main.py</p>
<p> 上面命令中的 -F 选项指定生成单个的可执行程序，-w 选项指定生成图形用户界面程序（不需要命令行界面）。运行上面命令，该工具同样在 dbapp 目录下生成了一个 dist 子目录，并在该子目录下生成了一个 main.exe 文件。</p>
<p> 直接双击运行 main.exe 程序（该程序有图形用户界面，因此可以双击运行），读者可自行查看运行结果。</p>
<h1 id="Python扩展知识"><a href="#Python扩展知识" class="headerlink" title="Python扩展知识"></a>Python扩展知识</h1><h2 id="图片转字节串"><a href="#图片转字节串" class="headerlink" title="图片转字节串"></a>图片转字节串</h2><ol>
<li><p>读取图片</p>
</li>
<li><p>使用base64编码图片，获得字符串</p>
</li>
<li><p>把字符串赋予一个变量</p>
</li>
<li><p>把变量写入py文件（可以在py文件的上层建立一个文件夹例如： a&#x2F;b.py ，这个b.py文件里面只有一个变量v&#x3D;base64编码后的字节串）</p>
</li>
<li><p>导入 from a.b import v</p>
</li>
<li><p>对v解编码并保存到新文件里</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#把图片写成py文件</span></span><br><span class="line"><span class="keyword">import</span> base64</span><br><span class="line">open_icon = <span class="built_in">open</span>(<span class="string">&quot;wangwei.ico&quot;</span>,<span class="string">&quot;rb&quot;</span>)</span><br><span class="line">b64str = base64.b64encode(open_icon.read())</span><br><span class="line">open_icon.close()</span><br><span class="line">write_data = <span class="string">&quot;img = %s&quot;</span> % b64str</span><br><span class="line">f = <span class="built_in">open</span>(<span class="string">&quot;b.py&quot;</span>,<span class="string">&quot;w+&quot;</span>)</span><br><span class="line">f.write(write_data)</span><br><span class="line">f.close()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#把字符串写成图片</span></span><br><span class="line"><span class="keyword">from</span> a.b <span class="keyword">import</span> img</span><br><span class="line"><span class="keyword">import</span> base64</span><br><span class="line">picture = <span class="built_in">open</span>(<span class="string">&quot;picture.ico&quot;</span>,<span class="string">&quot;wb+&quot;</span>)</span><br><span class="line">picture.write(base64.b64decode(img))</span><br><span class="line">picture.close()</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ol>
<h1 id="Python网站flask开发"><a href="#Python网站flask开发" class="headerlink" title="Python网站flask开发"></a>Python网站flask开发</h1><h2 id="骨干架构"><a href="#骨干架构" class="headerlink" title="骨干架构"></a>骨干架构</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> flask <span class="keyword">import</span> Flask</span><br><span class="line"></span><br><span class="line">app = Flask(__name__)</span><br><span class="line"></span><br><span class="line"><span class="meta">@app.route(<span class="params"><span class="string">&quot;/web01&quot;</span></span>)</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">index</span>():</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;中国移动&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    app.run()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="引入模板文件"><a href="#引入模板文件" class="headerlink" title="引入模板文件"></a>引入模板文件</h2><p>在项目目录下创建 templates目录，默认模板文 html存放在这个目录里面。也可以通过参数指定其他目录。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> flask <span class="keyword">import</span> Flask,render_template</span><br><span class="line"></span><br><span class="line">app = Flask(__name__)</span><br><span class="line"></span><br><span class="line"><span class="meta">@app.route(<span class="params"><span class="string">&quot;/web01&quot;</span></span>)</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">index</span>():</span><br><span class="line">    <span class="keyword">return</span> render_template(<span class="string">&quot;index.html&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    app.run()</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h1 id="前端知识"><a href="#前端知识" class="headerlink" title="前端知识"></a>前端知识</h1><h2 id="HTML"><a href="#HTML" class="headerlink" title="HTML"></a>HTML</h2><h5 id="标签："><a href="#标签：" class="headerlink" title="标签："></a>标签：</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">div和span  素段</span></span><br><span class="line">	div是块标签，span是行内标签</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">a 超链接</span></span><br><span class="line">	&lt;a href=&quot;http://www.baidu.com&quot;&gt;百度&lt;/a&gt;</span><br><span class="line">	&lt;a href=&quot;/web02&quot;&gt;自己的第2个页面&lt;/a&gt;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">img 图片</span></span><br><span class="line">	&lt;img src=&quot;http://图片地址&quot; style=&quot;height:100px; width:200px&quot;/&gt;</span><br><span class="line">	&lt;img src=&quot;/static/ww.jpg&quot; style=&quot;&quot; /&gt;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">_blank 在新的Tab页面打开</span></span><br><span class="line">    &lt;a href=&quot;http://www.baidu.com&quot; target=&quot;_blank&quot;&gt;</span><br><span class="line">        &lt;img src=&quot;/static/ww.jpg&quot; style=&quot;height:50px&quot;/&gt;</span><br><span class="line">    &lt;/a&gt;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">li  列表</span></span><br><span class="line">	ul和li  无序列表</span><br><span class="line">	ol和li  数字列表</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">table 表格</span></span><br><span class="line">	&lt;table border=&quot;1&quot;&gt;</span><br><span class="line">	thead	表头定义</span><br><span class="line">	tbody	表体</span><br><span class="line">	tr		行</span><br><span class="line">	th		表头的列</span><br><span class="line">	td		列</span><br><span class="line"><span class="meta prompt_">	</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">input 输入系列</span></span><br><span class="line">	&lt;input type=&quot;test&quot;&gt;</span><br><span class="line">	&lt;input type=&quot;password&quot;&gt;</span><br><span class="line">	&lt;input type=&quot;file&quot;&gt;</span><br><span class="line">	&lt;input type=&quot;radio&quot; name=&quot;n1&quot;&gt;男</span><br><span class="line">	&lt;input type=&quot;radio&quot; name=&quot;n1&quot;&gt;女</span><br><span class="line">	&lt;input type=&quot;checkbox&quot;&gt;篮球</span><br><span class="line">	&lt;input type=&quot;checkbox&quot;&gt;足球</span><br><span class="line">	&lt;input type=&quot;checkbox&quot;&gt;乒乓球</span><br><span class="line">	&lt;input type=&quot;button&quot; value=&quot;提交&quot;&gt; 普通按钮</span><br><span class="line">	&lt;input type=&quot;submit&quot; value=&quot;提交&quot;&gt; 提交表单</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="keyword">select</span> 下拉框</span></span><br><span class="line">	&lt;select&gt;          单选下拉框</span><br><span class="line">	&lt;select multiple&gt; 多选下拉框</span><br><span class="line">	&lt;option&gt;   项</span><br><span class="line"><span class="meta prompt_">	</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">textarea 多行文本</span></span><br><span class="line">	&lt;textarea rows=&quot;5&quot;&gt;</span><br><span class="line"><span class="meta prompt_">	</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">form 表单</span></span><br><span class="line">	method=&quot;get&quot; or &quot;post&quot;</span><br><span class="line">	action=&quot;/xxx/xx&quot;</span><br><span class="line">	表单里面的每个标签必须有name字段，不然不知道把input赋值给谁。</span><br><span class="line">	必须有一个submit标签。</span><br><span class="line">	flask里面用request.form就可以接收到form表单提交过来的数据。</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="CSS"><a href="#CSS" class="headerlink" title="CSS"></a>CSS</h2><h5 id="引用："><a href="#引用：" class="headerlink" title="引用："></a>引用：</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">方法1：直接写</span></span><br><span class="line">&lt;div style=&quot;color:red;&quot;&gt;中国联通&lt;/div&gt;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">方法2：写在<span class="built_in">head</span>里面。</span> </span><br><span class="line">&lt;head&gt;</span><br><span class="line">	&lt;style&gt;</span><br><span class="line">		.c01&#123;</span><br><span class="line">			color:red;</span><br><span class="line">		&#125;</span><br><span class="line">	&lt;/style&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">	&lt;h1 class=&quot;c01&quot;&gt;用户登录&lt;/h1&gt;</span><br><span class="line">&lt;/body&gt;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">方法3：写在专门的css文件里面(文件需要放在static文件夹里面)</span></span><br><span class="line">&lt;head&gt;</span><br><span class="line">	&lt;link rel=&quot;stylesheet&quot; href=&quot;file01.css&quot; /&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="css选择器："><a href="#css选择器：" class="headerlink" title="css选择器："></a>css选择器：</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">css选择器：</span></span><br><span class="line">	类选择器：  用.取名，class引用。</span><br><span class="line">	id选择器：  用#取名，id引用。</span><br><span class="line">	标签选择器： 用标签，无需引用。</span><br><span class="line">	属性选择器：用上述三种+[属性名=“属性值”] </span><br><span class="line">	后1代选择器：用上述三种&gt;标签</span><br><span class="line">	后的选择器： 用上述三种 标签</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">多个样式叠加覆盖：</span></span><br><span class="line">	覆盖是以css文件书写的下面的会覆盖上面的。如果不想自己被覆盖，可以在值后面加 !important</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="样式："><a href="#样式：" class="headerlink" title="样式："></a>样式：</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">样式：</span></span><br><span class="line">	高度 height: 90px;</span><br><span class="line">	宽度 width:  90px; / 支持百分比;（注明：行内标签，设置高度和宽度无效.）</span><br><span class="line">	显示 display: inline-block;  (行内块级兼顾)</span><br><span class="line">	边框 border: 1px solid #dddddd;  （虚线dotted，transparent透明色）</span><br><span class="line">	边框圆角 border-radius: 10px;</span><br><span class="line">	背景色 background-color:red;</span><br><span class="line">	</span><br><span class="line">	字体颜色 color: #00ff7f;</span><br><span class="line">	字体大小 font-size: 58px;</span><br><span class="line">	字体加粗 font-weight: 600;</span><br><span class="line">	字体字体 font-family: Arial,Verdana,Sans-serif;</span><br><span class="line">	文字水平居中 text-align: center;</span><br><span class="line">	文字垂直居中 line-height: 90px;</span><br><span class="line">	</span><br><span class="line">	浮动 float: left;  (left/center/right/)（注明：浮动会导致漂了，脱离文档流）</span><br><span class="line">	浮动拽回 &lt;div class=&quot;clear:both&quot;&gt;&lt;/div&gt;</span><br><span class="line">	</span><br><span class="line">	内边距 padding: 20px;</span><br><span class="line">	外边距 margin： 20px;</span><br><span class="line">	区域居中 margin: 0 auto;  (注明：如果是4个数字:上右下左；如果是2个数字：上下和左右；如果是3个数字：上和左右和下；)</span><br><span class="line">	</span><br><span class="line">	下划线 text-decoration: none;  </span><br><span class="line">	透明度  opacity: 0.5;</span><br><span class="line">	</span><br><span class="line">	热点.c1:hover标签的颜色修改 color:red;       （伪类）</span><br><span class="line">	追加.c1:after标签的内容追加 content:&quot;大帅哥&quot;; （伪类）</span><br><span class="line">	</span><br><span class="line">	层 z-indes: 99;</span><br><span class="line">	固定定位 position: fixed;</span><br><span class="line">	相对定位 position: relative; （参照物）</span><br><span class="line">	相对定位 position: absolute; （待定位物体）</span><br><span class="line">	</span><br><span class="line">	鼠标cursor: pointer （小手）</span><br><span class="line">	</span><br><span class="line">	&amp;nbsp; 半角的不断行的空白格（推荐使用）</span><br><span class="line">    &amp;ensp; 半角的空格</span><br><span class="line">    &amp;emsp; 全角的空格</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="BootStrap"><a href="#BootStrap" class="headerlink" title="BootStrap"></a>BootStrap</h2><p>​		下载用于生产环境的 Bootstrap：<a target="_blank" rel="noopener" href="https://github.com/twbs/bootstrap/releases/download/v3.4.1/bootstrap-3.4.1-dist.zip">https://github.com/twbs/bootstrap/releases/download/v3.4.1/bootstrap-3.4.1-dist.zip</a></p>
<p>中文文档：<a target="_blank" rel="noopener" href="https://v3.bootcss.com/">https://v3.bootcss.com/</a></p>
<p>​		还有一个专门做css图表的库，我们也可以区下载和引入一下font-awesome-4.7.0和bootstrap放在同一个目录static&#x2F;plugins&#x2F;目录下：<a target="_blank" rel="noopener" href="https://static.runoob.com/download/font-awesome-4.7.0.zip">https://static.runoob.com/download/font-awesome-4.7.0.zip</a> 。 找图标直接去菜鸟就行：<a target="_blank" rel="noopener" href="https://www.runoob.com/font-awesome/fontawesome-tutorial.html">https://www.runoob.com/font-awesome/fontawesome-tutorial.html</a></p>
<p>​		解压到项目static&#x2F;plugins目录，引用即可。</p>
<h5 id="示例如下："><a href="#示例如下：" class="headerlink" title="示例如下："></a>示例如下：</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=&quot;en&quot;&gt;</span><br><span class="line"></span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;</span><br><span class="line">    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</span><br><span class="line">    &lt;title&gt;Document&lt;/title&gt;</span><br><span class="line">    &lt;!-- 开发版本 --&gt;</span><br><span class="line">    &lt;link rel=&quot;stylesheet&quot; href=&quot;static/plugins/bootstrap-3.4.1/css/bootstrap.css&quot;&gt;</span><br><span class="line">    &lt;!-- 生成版本 --&gt;</span><br><span class="line">    &lt;!-- &lt;link rel=&quot;stylesheet&quot; href=&quot;static/plugins/bootstrap-3.4.1/css/bootstrap.min.css&quot;&gt; --&gt;</span><br><span class="line"></span><br><span class="line">&lt;/head&gt;</span><br><span class="line"></span><br><span class="line">&lt;body&gt;</span><br><span class="line">    &lt;input type=&quot;button&quot; value=&quot;提交&quot;&gt;</span><br><span class="line">    &lt;input type=&quot;button&quot; value=&quot;提交&quot; class=&quot;btn btn-primary&quot;&gt;</span><br><span class="line">    &lt;input type=&quot;button&quot; value=&quot;提交&quot; class=&quot;btn btn-success&quot;&gt;</span><br><span class="line">    &lt;input type=&quot;button&quot; value=&quot;提交&quot; class=&quot;btn btn-danger&quot;&gt;</span><br><span class="line">    &lt;input type=&quot;button&quot; value=&quot;提交&quot; class=&quot;btn btn-danger btn-xs&quot;&gt;    </span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line"></span><br><span class="line">&lt;/html&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h5 id="发现了django-mdeditor这个库"><a href="#发现了django-mdeditor这个库" class="headerlink" title="发现了django-mdeditor这个库"></a>发现了django-mdeditor这个库</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">https://github.com/pylixm/django-mdeditor?spm=a2c6h.12873639.article-detail.13.3ca172be9dA1UA</span></span><br><span class="line">pip3 install django-mdeditor</span><br><span class="line">注明：没用上，以后再研究吧。</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="编辑md文档–bootstrap-markdown编辑器"><a href="#编辑md文档–bootstrap-markdown编辑器" class="headerlink" title="编辑md文档–bootstrap-markdown编辑器"></a>编辑md文档–bootstrap-markdown编辑器</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">https://blog.csdn.net/coder1998/article/details/106325731</span></span><br><span class="line">下载，引入，textarea即可。</span><br><span class="line">&lt;textarea id=&quot;editor&quot; type=&quot;text&quot; name=&quot;desc&quot; data-provide=&quot;markdown&quot; rows=&quot;10&quot;&gt;</span><br><span class="line">&lt;/textarea&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h5 id="显示md文档–基础知识"><a href="#显示md文档–基础知识" class="headerlink" title="显示md文档–基础知识"></a>显示md文档–基础知识</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">https://blog.csdn.net/Kevinhanser/article/details/121374767</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">pip install markdown <span class="comment">#view视图中获取到数据库的数据，修饰为html语句，传到前端</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">pip install Pygments <span class="comment">#实现代码高亮</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装第二个包后还要执行</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">pygmentize -S default -f html -a .codehilite &gt; markdown_highlighy.css</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">pygmentize -S default -f html -a .codehilite &gt; default.css</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">pygmentize -S monokai  -f html -a .codehilite &gt; monokai.css</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"></span></span><br><span class="line"><span class="language-bash">pygmentize -S stata-light -f html -a .codehilite &gt; markdown_highlighy.css</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看支持的风格</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">from pygments.styles import STYLE_MAP</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="keyword">for</span> key <span class="keyword">in</span> STYLE_MAP.keys():</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">    <span class="built_in">print</span>(key)</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">https://blog.csdn.net/mouday/article/details/83114164</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"></span></span><br><span class="line"><span class="language-bash"><span class="comment"># 在文件夹下会发现生成了code.css文件，将这个css文件加入到你的static文件夹下css里面(路径自己定，只要用的时候引入正确就行了)</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">最后一步在需要高亮的html文件里面导入刚刚生成的css文件，例如我的是-&gt;要在</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">&lt;<span class="built_in">link</span> rel=<span class="string">&quot;stylesheet&quot;</span> <span class="built_in">type</span>=<span class="string">&quot;text/css&quot;</span> href=<span class="string">&quot;&#123;% static &#x27;static/css/markdown_highlighy.css&#x27; %&#125;&quot;</span>&gt;  &#123;<span class="comment">#语法高亮#&#125;</span></span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="显示md文档–python数据部分"><a href="#显示md文档–python数据部分" class="headerlink" title="显示md文档–python数据部分"></a>显示md文档–python数据部分</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">detail</span>(<span class="params">req</span>):</span><br><span class="line">    <span class="built_in">id</span> = req.GET.get(<span class="string">&#x27;id&#x27;</span>, default=<span class="number">5</span>)</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;\n开始连接数据库\n&quot;</span>)</span><br><span class="line">    conn = jaydebeapi.connect(<span class="string">&quot;com.gbasedbt.jdbc.Driver&quot;</span>,</span><br><span class="line">                                <span class="string">&quot;jdbc:gbasedbt-sqli://1.1.1.66:9083/testdb:GBASEDBTSERVER=g330;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=60&quot;</span>,</span><br><span class="line">                                [<span class="string">&quot;gbasedbt&quot;</span>, <span class="string">&quot;GBase123&quot;</span>],</span><br><span class="line">                                <span class="string">&quot;gbasedbtjdbc_3.3.0_2_36477d.jar&quot;</span></span><br><span class="line">                                )</span><br><span class="line">    mycursor = conn.cursor()</span><br><span class="line">    <span class="comment"># create table blog(id serial not null,name varchar(1024),blog text, time  datetime year to second default current year to second);</span></span><br><span class="line">    <span class="comment"># mycursor.execute(&quot;insert into blog(name,blog) values(?,?)&quot; , (&#x27;aaa&#x27;,&#x27;bbbbbb&#x27;))</span></span><br><span class="line">    sql0 = <span class="string">&quot;select * from blog;&quot;</span></span><br><span class="line">    sql = <span class="string">&quot;select * from blog where id=&#x27;&quot;</span>+<span class="built_in">str</span>(<span class="built_in">id</span>)+<span class="string">&quot;&#x27;;&quot;</span></span><br><span class="line">    mycursor.execute(sql)</span><br><span class="line">    rows = mycursor.fetchall()</span><br><span class="line">    namet=<span class="string">&quot;&quot;</span></span><br><span class="line">    blogt=<span class="string">&quot;&quot;</span></span><br><span class="line">    idt=<span class="string">&quot;&quot;</span></span><br><span class="line">    <span class="keyword">for</span> i,(<span class="built_in">id</span>,name,blog,time) <span class="keyword">in</span> <span class="built_in">enumerate</span>(rows):</span><br><span class="line">        <span class="comment"># print(i,id,name,blog,time)</span></span><br><span class="line">        idt=<span class="built_in">id</span></span><br><span class="line">        namet=name</span><br><span class="line">        blogt=blog</span><br><span class="line">    mycursor.close()</span><br><span class="line">    conn.close()</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;\nPython JayDeBeApi JDBC 测试程序结束运行.\n&quot;</span>)</span><br><span class="line">    blogmd = markdown.markdown(blogt,</span><br><span class="line">        extensions=[</span><br><span class="line">            <span class="string">&#x27;markdown.extensions.extra&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;markdown.extensions.codehilite&#x27;</span>,</span><br><span class="line">            <span class="string">&#x27;markdown.extensions.toc&#x27;</span>,</span><br><span class="line">        ])</span><br><span class="line">    <span class="keyword">return</span> render(req, <span class="string">&quot;blog/03.文章详情页面.html&quot;</span>,&#123;<span class="string">&quot;idt&quot;</span>:idt,<span class="string">&quot;namet&quot;</span>:namet,<span class="string">&quot;blogmd&quot;</span>:blogmd&#125;)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h5 id="显示md文档–网页展示部分"><a href="#显示md文档–网页展示部分" class="headerlink" title="显示md文档–网页展示部分"></a>显示md文档–网页展示部分</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>文章详情<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static/plugins/bootstrap-3.4.1/css/bootstrap.css&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static/plugins/font-awesome-4.7.0/css/font-awesome.css&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static/css/bootstrap-markdown.min.css&quot;</span> <span class="attr">type</span>=<span class="string">&quot;text/css&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static/css/markdown_highlighy.css&quot;</span> <span class="attr">type</span>=<span class="string">&quot;text/css&quot;</span> &gt;</span>  &#123;#语法高亮#&#125;</span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span><br><span class="line"><span class="language-css">      <span class="comment">/* 样式代码 */</span></span></span><br><span class="line"><span class="language-css">      <span class="selector-class">.blockCenter</span> &#123;</span></span><br><span class="line"><span class="language-css">        <span class="attribute">width</span>: <span class="number">90%</span>;</span></span><br><span class="line"><span class="language-css">        <span class="attribute">margin</span>: <span class="number">0</span> auto;</span></span><br><span class="line"><span class="language-css">        <span class="attribute">border-radius</span>: <span class="number">0%</span>;</span></span><br><span class="line"><span class="language-css">      &#125;</span></span><br><span class="line"><span class="language-css">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">body</span> <span class="attr">class</span>=<span class="string">&quot;blockCenter&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- HTML代码 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h2</span>&gt;</span>&#123;&#123; namet &#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">      &#123;% comment %&#125; <span class="tag">&lt;<span class="name">textarea</span> <span class="attr">name</span>=<span class="string">&quot;content&quot;</span> <span class="attr">data-provide</span>=<span class="string">&quot;markdown&quot;</span> <span class="attr">rows</span>=<span class="string">&quot;36&quot;</span>&gt;</span>&#123;&#123; blogmd &#125;&#125;<span class="tag">&lt;/<span class="name">textarea</span>&gt;</span> &#123;% endcomment %&#125;</span><br><span class="line">      &#123;% comment %&#125; <span class="tag">&lt;<span class="name">textarea</span> <span class="attr">id</span>=<span class="string">&quot;editor&quot;</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;desc&quot;</span> <span class="attr">data-provide</span>=<span class="string">&quot;markdown&quot;</span> <span class="attr">rows</span>=<span class="string">&quot;10&quot;</span>&gt;</span>&#123;&#123; blogmd &#125;&#125;<span class="tag">&lt;/<span class="name">textarea</span>&gt;</span> &#123;% endcomment %&#125;</span><br><span class="line">      上面是编辑窗口，下面是显示窗口。</span><br><span class="line">      &#123;&#123; blogmd|safe &#125;&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">      </span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;static/js/jquery-3.6.3.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;static/plugins/bootstrap-3.4.1/js/bootstrap.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;static/js/bootstrap-markdown.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//编辑窗口的自定义设置：</span></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span>  markDownObj = $(<span class="string">&quot;#editor&quot;</span>).<span class="title function_">markdown</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">             <span class="attr">autofocus</span>: <span class="literal">true</span>,<span class="comment">//编辑器实例化之后自动聚焦操作</span></span></span><br><span class="line"><span class="language-javascript">             <span class="attr">savable</span>:<span class="literal">true</span> <span class="comment">//编辑器实例化之后有保存按钮 这里不需要 设置为false</span></span></span><br><span class="line"><span class="language-javascript">         &#125;)</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        $(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="comment">//JavaScript代码</span></span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h2><h5 id="骨架示例："><a href="#骨架示例：" class="headerlink" title="骨架示例："></a>骨架示例：</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">div</span> <span class="attr">onclick</span>=<span class="string">&quot;myFunc()&quot;</span>&gt;</span>点击这里<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">		<span class="keyword">function</span> <span class="title function_">myFunc</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">			<span class="comment">//alert(&quot;你好呀&quot;);</span></span></span><br><span class="line"><span class="language-javascript">			<span class="title function_">confirm</span>(“是否继续？);</span></span><br><span class="line"><span class="language-javascript">		&#125;</span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">window</span>.<span class="property">history</span>.<span class="title function_">go</span>(-<span class="number">1</span>);  <span class="comment">//返回上一页</span></span></span><br><span class="line"><span class="language-javascript">		<span class="variable language_">window</span>.<span class="property">history</span>.<span class="title function_">back</span>();  <span class="comment">//返回上一页</span></span></span><br><span class="line"><span class="language-javascript">		<span class="variable language_">window</span>.<span class="property">location</span>.<span class="title function_">go</span>(-<span class="number">1</span>); <span class="comment">//刷新上一页</span></span></span><br><span class="line"><span class="language-javascript"> </span></span><br><span class="line"><span class="language-javascript">		<span class="variable language_">window</span>.<span class="property">history</span>.<span class="title function_">back</span>();location.<span class="title function_">reload</span>();<span class="comment">//强行刷新(返回上一页刷新页面)</span></span></span><br><span class="line"><span class="language-javascript">        </span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">window</span>.<span class="property">location</span>.<span class="property">href</span> = <span class="string">&#x27;/login?username=admin&amp;password=admin&#x27;</span>;</span></span><br><span class="line"><span class="language-javascript">        </span></span><br><span class="line"><span class="language-javascript">	</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="定时器："><a href="#定时器：" class="headerlink" title="定时器："></a>定时器：</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">span</span> <span class="attr">id</span>=<span class="string">&quot;txt01&quot;</span> <span class="attr">class</span>=<span class="string">&quot;a&quot;</span>&gt;</span>接下来本篇文章就来给大家介绍<span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="symbol">&amp;emsp;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">function</span> <span class="title function_">show</span>(<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> tag = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;txt01&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> str = tag.<span class="property">innerText</span>;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> firstChar = str[<span class="number">0</span>];</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> otherStr = str.<span class="title function_">substring</span>(<span class="number">1</span>, str.<span class="property">length</span>);</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> newStr = otherStr + firstChar;</span></span><br><span class="line"><span class="language-javascript">            tag.<span class="property">innerText</span> = newStr;</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">        <span class="comment">// 定时器：每0.8秒执行一次</span></span></span><br><span class="line"><span class="language-javascript">        <span class="built_in">setInterval</span>(show,<span class="number">800</span>);</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="数组："><a href="#数组：" class="headerlink" title="数组："></a>数组：</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> v1 = [<span class="number">11</span>,<span class="number">22</span>,<span class="number">33</span>,<span class="number">44</span>];</span><br><span class="line">v1.<span class="title function_">push</span>(<span class="string">&quot;中国&quot;</span>);            <span class="comment">//尾部追加</span></span><br><span class="line">v1.<span class="title function_">unshift</span>(<span class="string">&quot;中国&quot;</span>);         <span class="comment">//头部追加</span></span><br><span class="line">v1.<span class="title function_">splice</span>(索引位置,<span class="number">0</span>,<span class="string">&quot;中国&quot;</span>); <span class="comment">//指定位置追加</span></span><br><span class="line">v1.<span class="title function_">pop</span>()      <span class="comment">//尾部删除</span></span><br><span class="line">v1.<span class="title function_">shift</span>()    <span class="comment">//头部删除</span></span><br><span class="line">v1.<span class="title function_">splice</span>(索引位置,<span class="number">1</span>) <span class="comment">//指定位置删除</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> ( <span class="keyword">var</span> idx <span class="keyword">in</span> v1)&#123;</span><br><span class="line">    <span class="comment">//0,1,2,3</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i=<span class="number">0</span>; i&lt;v1.<span class="property">lenth</span>; i++)&#123;</span><br><span class="line">    <span class="comment">//do</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="动态web列表："><a href="#动态web列表：" class="headerlink" title="动态web列表："></a>动态web列表：</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ul</span> <span class="attr">id</span>=<span class="string">&quot;city&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//发送网络请求，获得数据给cityList赋值</span></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span> cityList = [<span class="string">&quot;北京&quot;</span>,<span class="string">&quot;上海&quot;</span>,<span class="string">&quot;深圳&quot;</span>];</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">for</span>(<span class="keyword">var</span> i <span class="keyword">in</span> cityList)&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> text = cityList[i];</span></span><br><span class="line"><span class="language-javascript">            <span class="comment">//创建&lt;li&gt;&lt;/li&gt;</span></span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> tag = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;li&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">            tag.<span class="property">innerText</span> = text;</span></span><br><span class="line"><span class="language-javascript">            <span class="comment">//关联父对象ul</span></span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> parentTag = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;city&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">            parentTag.<span class="title function_">appendChild</span>(tag);</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="对象-字典"><a href="#对象-字典" class="headerlink" title="对象(字典):"></a>对象(字典):</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">info = &#123;</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&quot;张三&quot;</span>,</span><br><span class="line">    <span class="attr">age</span>:<span class="number">18</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> key <span class="keyword">in</span> info)&#123;</span><br><span class="line">	<span class="comment">// key=name/age</span></span><br><span class="line">    <span class="comment">// data=info[key]</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="获取web输入框的内容"><a href="#获取web输入框的内容" class="headerlink" title="获取web输入框的内容:"></a>获取web输入框的内容:</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;请输入内容&quot;</span> <span class="attr">id</span>=<span class="string">&quot;txtUser&quot;</span> /&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    	<span class="keyword">var</span> webTag = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;txtUser&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span> str = webTag.<span class="property">value</span>;</span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">console</span>.<span class="title function_">log</span>(str);</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="DOM和事件-点击添加-："><a href="#DOM和事件-点击添加-：" class="headerlink" title="DOM和事件(点击添加)："></a>DOM和事件(点击添加)：</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">value</span>=<span class="string">&quot;点击添加&quot;</span> <span class="attr">oncheck</span>=<span class="string">&quot;addCity()&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">ul</span> <span class="attr">id</span>=<span class="string">&quot;city&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    	<span class="keyword">function</span> <span class="title function_">addCity</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> newTag = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;li&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">            newTag.<span class="property">innerText</span> = <span class="string">&quot;天然&quot;</span>;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> webTag = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;city&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">            webTab.<span class="title function_">appendChild</span>(newTag);</span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="jQuery"><a href="#jQuery" class="headerlink" title="jQuery"></a>jQuery</h2><h5 id="获取input内容，创建li，添加li-："><a href="#获取input内容，创建li，添加li-：" class="headerlink" title="获取input内容，创建li，添加li ："></a>获取input内容，创建li，添加li ：</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>jQuery测试<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static\plugins\font-awesome-4.7.0\css\font-awesome.css&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static\plugins\bootstrap-3.4.1\css\bootstrap.css&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 录入界面 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span>&gt;</span>jQuery测试<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">span</span>&gt;</span>标题<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">id</span>=<span class="string">&quot;biaoti&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cinput&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;输入标题&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">span</span>&gt;</span>内容<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">textarea</span> <span class="attr">name</span>=<span class="string">&quot;&quot;</span> <span class="attr">cols</span>=<span class="string">&quot;30&quot;</span> <span class="attr">rows</span>=<span class="string">&quot;10&quot;</span> <span class="attr">id</span>=<span class="string">&quot;neirong&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cinput&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;输入内容&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">textarea</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">id</span>=<span class="string">&quot;tijiao&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cbutton&quot;</span> <span class="attr">value</span>=<span class="string">&quot;提交&quot;</span> <span class="attr">onclick</span>=<span class="string">&quot;f01()&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">&lt;!-- 展示界面 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">ul</span> <span class="attr">id</span>=<span class="string">&quot;liebiao&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cdl&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!-- 脚本 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;static/js/jquery-3.6.3.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">function</span> <span class="title function_">f01</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> bt = $(<span class="string">&quot;#biaoti&quot;</span>).<span class="title function_">val</span>()</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> nr = $(<span class="string">&quot;#neirong&quot;</span>).<span class="title function_">val</span>()   <span class="comment">//获取值</span></span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> btnr = bt+nr</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> li = $(<span class="string">&quot;&lt;li&gt;&quot;</span>).<span class="title function_">text</span>(btnr)  <span class="comment">//创建标签</span></span></span><br><span class="line"><span class="language-javascript">            $(<span class="string">&quot;.cdl&quot;</span>).<span class="title function_">append</span>(li)           <span class="comment">//锚定标签</span></span></span><br><span class="line"><span class="language-javascript">        &#125;</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="选择器："><a href="#选择器：" class="headerlink" title="选择器："></a>选择器：</h5><p>​		$(“#id01”)  通过ID定位</p>
<p>​		$(“.class01”)  通过class定位 </p>
<p>​		$(“h2”)  通过标签定位</p>
<p>​		$(“.c1 .c2 a”)  层级选择器 </p>
<p>​		$(“.c1,.c2,a”) 多选择器</p>
<p>​		 $(“input[name&#x3D;’n01’]”)  通过标签和标签属性定位 </p>
<p>​		onckick&#x3D;”fun01(this);”  点击执行函数并传入当前this，再通过$(this)可以获取该标签。</p>
<p>​		.next 下一个</p>
<p>​		.prev 上一个</p>
<p>​		.parent 父</p>
<p>​		.siblings 兄弟们</p>
<p>​		.children() 孩子们</p>
<p>​		.children(“.p10”) 孩子们中样式等于p10的</p>
<p>​		.find(“.p10”)  子孙中样式等于p10的</p>
<p>​		</p>
<h5 id="样式操作："><a href="#样式操作：" class="headerlink" title="样式操作："></a>样式操作：</h5><p>​		addClass</p>
<p>​		removeClass</p>
<p>​		hasClass</p>
<h5 id="批量绑定事件"><a href="#批量绑定事件" class="headerlink" title="批量绑定事件:"></a>批量绑定事件:</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>aaa<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>bbb<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>ccc<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">	$(<span class="string">&quot;li&quot;</span>).<span class="title function_">click</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//点击li标签时，执行函数</span></span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//$(this)当前点击的是哪个标签</span></span></span><br><span class="line"><span class="language-javascript">    &#125;);</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="标准的HTML页面："><a href="#标准的HTML页面：" class="headerlink" title="标准的HTML页面："></a>标准的HTML页面：</h2><h5 id="我的html框架模板"><a href="#我的html框架模板" class="headerlink" title="我的html框架模板"></a>我的html框架模板</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>示例页面<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static/plugins/bootstrap-3.4.1/css/bootstrap.css&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;stylesheet&quot;</span> <span class="attr">href</span>=<span class="string">&quot;static/plugins/font-awesome-4.7.0/css/font-awesome.css&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span><br><span class="line"><span class="language-css">        <span class="comment">/* 样式代码 */</span></span></span><br><span class="line"><span class="language-css">        <span class="selector-class">.blockCenter</span> &#123;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">width</span>: <span class="number">90%</span>;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">margin</span>: <span class="number">0</span> auto;</span></span><br><span class="line"><span class="language-css">            <span class="attribute">border-radius</span>: <span class="number">0%</span>;</span></span><br><span class="line"><span class="language-css">        &#125;</span></span><br><span class="line"><span class="language-css">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">class</span>=<span class="string">&quot;blockCenter&quot;</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- HTML代码 --&gt;</span></span><br><span class="line">    </span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;static/js/jquery-3.6.3.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;static/plugins/bootstrap-3.4.1/js/bootstrap.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        $(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="comment">//JavaScript代码</span></span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>







<h1 id="Python网站Django开发"><a href="#Python网站Django开发" class="headerlink" title="Python网站Django开发"></a>Python网站Django开发</h1><h2 id="安装jgango"><a href="#安装jgango" class="headerlink" title="安装jgango"></a>安装jgango</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pip3 install Django==4.1.7 -i https://pypi.tuna.tsinghua.edu.cn/simple</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>VSCode中安装Django插件：</p>
<p>​	文件–》首选项–》扩展，搜django安装</p>
<p>VSCode中安装Django插件后实现html语法提示：</p>
<p>​	右下角齿轮–》设置 –》做上角打开json设置 –》文件中添加如下内容</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">&quot;files.associations&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;**/*.html&quot;</span><span class="punctuation">:</span> <span class="string">&quot;html&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;**/templates/**/*.html&quot;</span><span class="punctuation">:</span> <span class="string">&quot;django-html&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;emmet.includeLanguages&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;django-html&quot;</span><span class="punctuation">:</span> <span class="string">&quot;html&quot;</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">进入你要存储项目的目录，执行创建项目的命令：</span></span><br><span class="line">cd D:\soft\src\Python3\Django</span><br><span class="line">django-admin startproject project01</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">项目目录文件介绍：</span></span><br><span class="line">project01</span><br><span class="line">  |-- manage.py          [项目管理，启动项目，创建APP,数据管理] [不要动]</span><br><span class="line">  |-- project01</span><br><span class="line">       |-- __init__.py</span><br><span class="line">       |-- settings.py   [项目配置]    [注册app，配置数据库]</span><br><span class="line">       |-- urls.py       [URL映射函数] [经常操作]</span><br><span class="line">       |-- asgi.py       [接受网络请求] [不要动]</span><br><span class="line">       |-- wsgi.py       [接受网络请求] [不要动]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="创建APP"><a href="#创建APP" class="headerlink" title="创建APP"></a>创建APP</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">说明：一个项目可以包含多个APP</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">创建APP命令如下：</span></span><br><span class="line">cd D:\soft\src\Python3\Django\project01</span><br><span class="line">C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/python.exe manage.py startapp app01</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">APP目录文件介绍：</span></span><br><span class="line">app01</span><br><span class="line">  |-- __init__.py         </span><br><span class="line">  |-- admin.py        [固定，不要动] django默认提供了admin后台管理</span><br><span class="line">  |-- apps.py         [固定，不要动] app启动类</span><br><span class="line">  |-- migrations      [固定，不要动] 数据库变更记录</span><br><span class="line">  |-- models.py       [重要] 对数据库操作</span><br><span class="line">  |-- tests.py        [固定，不要动] 单元测试</span><br><span class="line">  |-- views.py        [重要] 函数</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="注册APP-项目的settings-py"><a href="#注册APP-项目的settings-py" class="headerlink" title="注册APP (项目的settings.py)"></a>注册APP (项目的settings.py)</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">INSTALLED_APPS = [</span><br><span class="line">    &#x27;django.contrib.admin&#x27;,</span><br><span class="line">    &#x27;django.contrib.auth&#x27;,</span><br><span class="line">    &#x27;django.contrib.contenttypes&#x27;,</span><br><span class="line">    &#x27;django.contrib.sessions&#x27;,</span><br><span class="line">    &#x27;django.contrib.messages&#x27;,</span><br><span class="line">    &#x27;django.contrib.staticfiles&#x27;,</span><br><span class="line">    &#x27;app01.apps.App01Config&#x27;,</span><br><span class="line">]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="编写URL函数映射关系-（项目的urls-py）"><a href="#编写URL函数映射关系-（项目的urls-py）" class="headerlink" title="编写URL函数映射关系 （项目的urls.py）"></a>编写URL函数映射关系 （项目的urls.py）</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.contrib <span class="keyword">import</span> admin</span><br><span class="line"><span class="keyword">from</span> django.urls <span class="keyword">import</span> path</span><br><span class="line"><span class="keyword">from</span> app01 <span class="keyword">import</span> views</span><br><span class="line"></span><br><span class="line">urlpatterns = [</span><br><span class="line">    <span class="comment">#path(&#x27;admin/&#x27;, admin.site.urls),</span></span><br><span class="line">    path(<span class="string">&#x27;index/&#x27;</span>,views.index),</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="编写试图函数（APP的views-py"><a href="#编写试图函数（APP的views-py" class="headerlink" title="编写试图函数（APP的views.py)"></a>编写试图函数（APP的views.py)</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.shortcuts <span class="keyword">import</span> render,HttpResponse</span><br><span class="line"></span><br><span class="line"><span class="comment"># Create your views here.</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">index</span>(<span class="params">request</span>):</span><br><span class="line">    <span class="keyword">return</span> HttpResponse(<span class="string">&quot;欢迎使用&quot;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="启动jgango项目"><a href="#启动jgango项目" class="headerlink" title="启动jgango项目"></a>启动jgango项目</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cd D:\soft\src\Python3\Django\project01</span><br><span class="line">C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/python.exe manage.py runserver</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">注明：centos需要注释掉setting.py里面的database内容，再启动。</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="使用templates模板"><a href="#使用templates模板" class="headerlink" title="使用templates模板"></a>使用templates模板</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在APP的目录下创建templates目录</span></span><br><span class="line"><span class="comment">#在templates目录中编写html文件</span></span><br><span class="line"><span class="comment">#在views.py中返回模板页面</span></span><br><span class="line"><span class="keyword">return</span> render(request,<span class="string">&quot;aaa.html&quot;</span>,&#123;<span class="string">&quot;key01&quot;</span>:<span class="string">&quot;value01&quot;</span>&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="加载静态资源-图片-x2F-css文件-x2F-js文件-x2F-plugins插件"><a href="#加载静态资源-图片-x2F-css文件-x2F-js文件-x2F-plugins插件" class="headerlink" title="加载静态资源(图片&#x2F;css文件&#x2F;js文件&#x2F;plugins插件)"></a>加载静态资源(图片&#x2F;css文件&#x2F;js文件&#x2F;plugins插件)</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">在APP的目录下创建static目录。然</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">再在static目录下创建： img css js plugins 四个目录。</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">在html文件里面如果引用？</span></span><br><span class="line">	引用方式一： 直接写/static/.../xx.jpg即可（我就用这种写法）。</span><br><span class="line">	引用方式二： 在html第一行写 &#123;% load static %&#125; ， 在应用的地方写 &#123;% static .../xx.jpg %&#125;  （这种写法需要设置STATICFILES_DIRS）</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="for列表list-循环展示-html中使用for"><a href="#for列表list-循环展示-html中使用for" class="headerlink" title="for列表list-循环展示-html中使用for"></a>for列表list-循环展示-html中使用for</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">names=[<span class="string">&quot;aaa&quot;</span>,<span class="string">&quot;bbb&quot;</span>,<span class="number">111</span>,<span class="number">222</span>,<span class="number">333</span>]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;% <span class="keyword">for</span> item <span class="keyword">in</span> n %&#125;</span><br><span class="line">    &lt;span&gt;&#123;&#123; item&#125;&#125;&lt;/span&gt;&lt;br&gt;</span><br><span class="line">&#123;% endfor %&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明：直接取某个索引的值可以用.n</p>
<h2 id="for字典dict-循环展示-html中使用for"><a href="#for字典dict-循环展示-html中使用for" class="headerlink" title="for字典dict-循环展示-html中使用for"></a>for字典dict-循环展示-html中使用for</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">dict01=&#123;<span class="string">&quot;k1&quot;</span>:<span class="string">&quot;aaa&quot;</span>,<span class="string">&quot;k2&quot;</span>:<span class="string">&quot;bbb&quot;</span>,<span class="string">&quot;id&quot;</span>:<span class="number">26</span>&#125;</span><br><span class="line"><span class="keyword">return</span> render(req,<span class="string">&quot;blog/99tupian.html&quot;</span>,&#123;<span class="string">&quot;n&quot;</span>:names,<span class="string">&quot;d&quot;</span>:dict01&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;dl&gt;</span><br><span class="line">    &#123;% <span class="keyword">for</span> k,v <span class="keyword">in</span> d.<span class="property">items</span> %&#125;</span><br><span class="line">        &lt;li&gt;键：&#123;&#123;k&#125;&#125;  --&gt;  值：&#123;&#123;v&#125;&#125;&lt;/li&gt;</span><br><span class="line">    &#123;% endfor%&#125;</span><br><span class="line">&lt;/dl&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明：还可以循环d.keys 和 d.values</p>
<h2 id="if判断分支语句-html中使用if"><a href="#if判断分支语句-html中使用if" class="headerlink" title="if判断分支语句-html中使用if"></a>if判断分支语句-html中使用if</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;% <span class="keyword">if</span> a == <span class="string">&quot;111&quot;</span> %&#125;</span><br><span class="line">    &lt;h1&gt;<span class="number">11111111111</span>&lt;/h1&gt;</span><br><span class="line">&#123;% elif a == <span class="string">&quot;222&quot;</span> %&#125;</span><br><span class="line">    &lt;h1&gt;<span class="number">22222222222</span>&lt;/h1&gt;</span><br><span class="line">&#123;% <span class="keyword">else</span> %&#125;</span><br><span class="line">    &lt;h1&gt;oooooooooooooo&lt;/h1&gt;</span><br><span class="line">&#123;% endif %&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="请求和响应"><a href="#请求和响应" class="headerlink" title="请求和响应"></a>请求和响应</h2><ul>
<li>请求 def fun01(request):<ol>
<li>request是一个对象，它封装了用户发送过来的所有数据</li>
<li>获取方法类型：request.method</li>
<li>获取URL上传递的值：id &#x3D; req.GET.get(‘id’, default&#x3D;’10’)</li>
<li>获取请求体中传递的值：id &#x3D; request.POST.get(“id”,default&#x3D;’10’)</li>
</ol>
</li>
<li>响应<ol>
<li>返回字符串：HttpResponse(“aaaaa”)</li>
<li>返回HTML整个页面字符串： return render(request,”aaa.html”,{“kk”:”vvv”})</li>
<li>让浏览器跳转到其他页面：return redirect(“<a target="_blank" rel="noopener" href="https://www.baidu.com/">https://www.baidu.com</a>“)</li>
</ol>
</li>
</ul>
<h2 id="Ajax发送请求"><a href="#Ajax发送请求" class="headerlink" title="Ajax发送请求"></a>Ajax发送请求</h2><p>​	Ajax发送请求依赖jQuery.js</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">clickMe</span>(<span class="params"></span>)&#123;</span><br><span class="line">$.<span class="title function_">ajax</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;/abc&#x27;</span>,</span><br><span class="line">    <span class="attr">type</span>: <span class="string">&quot;get&quot;</span>,</span><br><span class="line">    <span class="comment">//type: &quot;post&quot;,</span></span><br><span class="line">    <span class="attr">data</span>: &#123;</span><br><span class="line">        <span class="attr">k01</span>: <span class="number">123</span>,</span><br><span class="line">        <span class="attr">k02</span>: <span class="string">&quot;abc&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">dateType</span>: <span class="string">&quot;JSON&quot;</span>,</span><br><span class="line">    <span class="attr">success</span>: <span class="keyword">function</span>(<span class="params">response</span>)&#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(response);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>说明：</p>
<ol>
<li><p>Ajax发送完请求取到的放回值只能给到HTML。</p>
</li>
<li><p>Ajax发送请求的时候就是把值传递给Python函数的时刻。</p>
</li>
<li><p>问题：那么Python如何主动去发送请求？</p>
<p>答：需要python的第三方模块requests，然后res&#x3D;requests.get(“<a target="_blank" rel="noopener" href="https://www.baidu.com/">https://www.baidu.com</a>“)</p>
</li>
</ol>
<h2 id="Ajax发送请求-带上input框的数据"><a href="#Ajax发送请求-带上input框的数据" class="headerlink" title="Ajax发送请求-带上input框的数据"></a>Ajax发送请求-带上input框的数据</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">id</span>=<span class="string">&quot;txtUser&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;姓名&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">function</span> <span class="title function_">clickMe</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">$.<span class="title function_">ajax</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">url</span>: <span class="string">&#x27;/abc&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">type</span>: <span class="string">&quot;get&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">    <span class="comment">//type: &quot;post&quot;,</span></span></span><br><span class="line"><span class="language-javascript">    <span class="attr">data</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">k01</span>: $&#123;”#txtUser“&#125;.<span class="title function_">val</span>()</span></span><br><span class="line"><span class="language-javascript">    &#125;,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">dateType</span>: <span class="string">&quot;JSON&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">    <span class="attr">success</span>: <span class="keyword">function</span>(<span class="params">response</span>)&#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="variable language_">console</span>.<span class="title function_">log</span>(response);</span></span><br><span class="line"><span class="language-javascript">    &#125;</span></span><br><span class="line"><span class="language-javascript">&#125;)</span></span><br><span class="line"><span class="language-javascript">&#125;</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="Ajax发送请求-带上表单内所有数据"><a href="#Ajax发送请求-带上表单内所有数据" class="headerlink" title="Ajax发送请求-带上表单内所有数据"></a>Ajax发送请求-带上表单内所有数据</h2><ol>
<li><p>代码基本上如上</p>
</li>
<li><p>只是给form表单一个id属性</p>
</li>
<li><p>再给每个input标签一个name属性</p>
</li>
<li><p>然后修改ajax里面的data值为：  </p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">data</span>: $(<span class="string">&quot;#form3&quot;</span>).<span class="title function_">serialize</span>(),</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="让自己的网站免除csrf-token认证"><a href="#让自己的网站免除csrf-token认证" class="headerlink" title="让自己的网站免除csrf _token认证"></a>让自己的网站免除csrf _token认证</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.views.decorators.csrf <span class="keyword">import</span> csrf_exempt</span><br><span class="line"></span><br><span class="line"><span class="meta">@csrf_exempt</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">text_ajax</span>(<span class="params">request</span>):</span><br><span class="line">    <span class="built_in">print</span>(request.GET)</span><br><span class="line">    <span class="built_in">print</span>(request.POST)</span><br><span class="line">    <span class="keyword">return</span> HttpResponse(<span class="string">&quot;68&quot;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="Ajax变更a标签为发送POST请求示例："><a href="#Ajax变更a标签为发送POST请求示例：" class="headerlink" title="Ajax变更a标签为发送POST请求示例："></a>Ajax变更a标签为发送POST请求示例：</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        <span class="comment">//这样a标签可以用ajax发送post请求，但是页面不能跳转,实践证明ajax请求一般用来获取json数据而不是网页。另外GET请求一样可传递data内容，也一样不能接受网页数据返回。</span></span></span><br><span class="line"><span class="language-javascript">        $(<span class="string">&#x27;#blog&#x27;</span>).<span class="title function_">on</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params">event</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">          event.<span class="title function_">preventDefault</span>() <span class="comment">//使a自带方法时效</span></span></span><br><span class="line"><span class="language-javascript">          $.<span class="title function_">ajax</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">type</span>: <span class="string">&#x27;POST&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">url</span>: <span class="string">&#x27;/login&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">dataType</span>: <span class="string">&#x27;JSON&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">data</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">              <span class="attr">username</span>: <span class="string">&#x27;admin&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">              <span class="attr">password</span>: <span class="string">&#x27;admin&#x27;</span></span></span><br><span class="line"><span class="language-javascript">            &#125;,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">result</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">              <span class="comment">//请求成功后的操作</span></span></span><br><span class="line"><span class="language-javascript">              <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;点击博客发送POST成功&quot;</span>)</span></span><br><span class="line"><span class="language-javascript">              <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span></span><br><span class="line"><span class="language-javascript">              <span class="variable language_">window</span>.<span class="property">location</span>.<span class="property">href</span> = <span class="string">&#x27;你的跳转的目标地址&#x27;</span>;</span></span><br><span class="line"><span class="language-javascript">            &#125;,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">error</span>: <span class="keyword">function</span> (<span class="params">result</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">              <span class="comment">//请求失败后的操作</span></span></span><br><span class="line"><span class="language-javascript">              <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;点击博客发送POST失败&quot;</span>)</span></span><br><span class="line"><span class="language-javascript">              <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">          &#125;)</span></span><br><span class="line"><span class="language-javascript">        &#125;)</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="让a标签以post方式提交"><a href="#让a标签以post方式提交" class="headerlink" title="让a标签以post方式提交"></a>让a标签以post方式提交</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">span</span> &gt;</span><span class="tag">&lt;<span class="name">body</span>&gt;</span> </span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;javascript:doPost(&quot;</span><span class="attr">addStudent.action</span>&quot;, &#123;&quot;<span class="attr">name</span>&quot;<span class="attr">:</span>&quot;<span class="attr">张三</span>&quot;&#125;)&quot;&gt;</span>提交<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"> </span></span><br><span class="line"><span class="language-javascript"><span class="keyword">function</span> <span class="title function_">doPost</span>(<span class="params">to, p</span>) &#123; <span class="comment">// to:提交动作（action）,p:参数 </span></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> myForm = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;form&quot;</span>); </span></span><br><span class="line"><span class="language-javascript">myForm.<span class="property">method</span> = <span class="string">&quot;post&quot;</span>; </span></span><br><span class="line"><span class="language-javascript">myForm.<span class="property">action</span> = to; </span></span><br><span class="line"><span class="language-javascript"><span class="keyword">for</span> (<span class="keyword">var</span> i <span class="keyword">in</span> p)&#123; </span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> myInput = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;input&quot;</span>); </span></span><br><span class="line"><span class="language-javascript">myInput.<span class="title function_">setAttribute</span>(<span class="string">&quot;name&quot;</span>, i); <span class="comment">// 为input对象设置name </span></span></span><br><span class="line"><span class="language-javascript">myInput.<span class="title function_">setAttribute</span>(<span class="string">&quot;value&quot;</span>, p[i]); <span class="comment">// 为input对象设置value </span></span></span><br><span class="line"><span class="language-javascript">myForm.<span class="title function_">appendChild</span>(myInput); </span></span><br><span class="line"><span class="language-javascript">&#125; </span></span><br><span class="line"><span class="language-javascript"><span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(myForm); </span></span><br><span class="line"><span class="language-javascript">myForm.<span class="title function_">submit</span>(); </span></span><br><span class="line"><span class="language-javascript"><span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(myForm); <span class="comment">// 提交后移除创建的form </span></span></span><br><span class="line"><span class="language-javascript">&#125; </span></span><br><span class="line"><span class="language-javascript">&lt;/scrip&gt; </span></span><br><span class="line"><span class="language-javascript">&lt;<span class="regexp">/body&gt;&lt;/</span>span&gt;</span></span><br><span class="line"><span class="language-javascript"></span></span><br></pre></td></tr></table></figure>



<h2 id="json"><a href="#json" class="headerlink" title="json"></a>json</h2><ul>
<li><p>编码 （返回json字符串）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">json_string = json.dumps(data_dict)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</li>
<li><p>解码   (反序列化)</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">json_dict = json.loads(json_string)</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- name: index.html --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;输入用户名&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;password&quot;</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;输入用户密码&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="tag">&lt;<span class="name">button</span> <span class="attr">class</span>=<span class="string">&quot;Send_AJAX&quot;</span>&gt;</span>发送数据<span class="tag">&lt;/<span class="name">button</span>&gt;</span><span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">&quot;ErrorTag&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://code.jquery.com/jquery-3.4.1.min.js&quot;</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    $(<span class="string">&quot;.Send_AJAX&quot;</span>).<span class="title function_">click</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span> username = $(<span class="string">&#x27;input[name=&quot;username&quot;]&#x27;</span>).<span class="title function_">val</span>();</span></span><br><span class="line"><span class="language-javascript">        <span class="keyword">var</span> passowrd = $(<span class="string">&#x27;input[name=&quot;password&quot;]&#x27;</span>).<span class="title function_">val</span>();</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">        $.<span class="title function_">ajax</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">url</span>:<span class="string">&quot;/_ajax/&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">type</span>:<span class="string">&quot;POST&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">contentType</span>:<span class="string">&quot;application/json;charset=utf-8&quot;</span>,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">data</span>:<span class="title class_">JSON</span>.<span class="title function_">stringify</span>(&#123; <span class="attr">username</span>: username, <span class="attr">password</span>: passowrd &#125;), <span class="comment">// 序列化</span></span></span><br><span class="line"><span class="language-javascript">            <span class="attr">success</span>:<span class="keyword">function</span> (<span class="params">data</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">var</span> data = <span class="title class_">JSON</span>.<span class="title function_">parse</span>(data);        <span class="comment">// 反序列化</span></span></span><br><span class="line"><span class="language-javascript">                <span class="keyword">if</span>(!data[<span class="string">&quot;flag&quot;</span>])&#123;</span></span><br><span class="line"><span class="language-javascript">                    $(<span class="string">&quot;.ErrorTag&quot;</span>).<span class="title function_">html</span>(<span class="string">&quot;用户名或密码错误&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">                &#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="language-javascript">                    $(<span class="string">&quot;.ErrorTag&quot;</span>).<span class="title function_">html</span>(<span class="string">&quot;密码输入正确&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">                &#125;</span></span><br><span class="line"><span class="language-javascript">            &#125;,</span></span><br><span class="line"><span class="language-javascript">            <span class="attr">error</span>:<span class="keyword">function</span> (<span class="params">data</span>) &#123;</span></span><br><span class="line"><span class="language-javascript">                <span class="title function_">alert</span>(<span class="string">&#x27;未知错误,数据通信失败!&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">            &#125;</span></span><br><span class="line"><span class="language-javascript">        &#125;);</span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="Django"><a href="#Django" class="headerlink" title="Django"></a>Django</h2><p>Django 教程 11: 部署 Django 到生产环境</p>
<p><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Django/Deployment">https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Django/Deployment</a></p>
<h1 id="Python连接GBase8s"><a href="#Python连接GBase8s" class="headerlink" title="Python连接GBase8s"></a>Python连接GBase8s</h1><h2 id="安装依赖通过JayDeBeApi连接数据库gbase330"><a href="#安装依赖通过JayDeBeApi连接数据库gbase330" class="headerlink" title="安装依赖通过JayDeBeApi连接数据库gbase330"></a>安装依赖通过JayDeBeApi连接数据库gbase330</h2><p>介质：D:\soft\05.工作记录\03.文档介质\GBase文档软件\330宜昌三峡机场\gbaseSoftCDROM宜昌三峡机场V8.8_3.3.0\GBase8sV8.8_3.3.0_RHEL6_x86_64\Setup</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">pip3 install JayDeBeApi</span></span><br><span class="line">---------------------------------------- 345.1/345.1 kB 1.9 MB/s eta 0:00:00</span><br><span class="line">Requirement already satisfied: packaging in c:\users\lenovo\appdata\local\programs\python\python310\lib\site-packages (from JPype1-&gt;JayDeBeApi) (23.0)</span><br><span class="line">Installing collected packages: JPype1, JayDeBeApi</span><br><span class="line">Successfully installed JPype1-1.4.1 JayDeBeApi-1.2.3</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">D:\soft\src\Python3\Django\project01&gt;java -version</span></span><br><span class="line">java version &quot;1.8.0_341&quot;</span><br><span class="line">Java(TM) SE Runtime Environment (build 1.8.0_341-b10)</span><br><span class="line">Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>上传jdbc驱动</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">D:\soft\src\Python3\Django\project01\gbasedbtjdbc_3.3.0_2_36477d.jar</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>views文件里面添加数据库访问代码</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">def detail(req):</span><br><span class="line">    id = req.GET.get(&#x27;id&#x27;, default=&#x27;10&#x27;)</span><br><span class="line">    print(&quot;\n开始连接数据库\n&quot;)</span><br><span class="line">    conn = jaydebeapi.connect(&quot;com.gbasedbt.jdbc.Driver&quot;,</span><br><span class="line">                                &quot;jdbc:gbasedbt-sqli://1.1.1.66:9083/testdb:GBASEDBTSERVER=g330;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=60&quot;,</span><br><span class="line">                                [&quot;gbasedbt&quot;, &quot;GBase123&quot;],</span><br><span class="line">                                &quot;gbasedbtjdbc_3.3.0_2_36477d.jar&quot;</span><br><span class="line">                                )</span><br><span class="line">    mycursor = conn.cursor()</span><br><span class="line">    mycursor.execute(&quot;drop table if exists company&quot;)</span><br><span class="line">    mycursor.execute(&quot;create table company(coid serial,coname varchar(255),coaddr text)&quot;)</span><br><span class="line">    mycursor.execute(&quot;insert into company(coname,coaddr) values (?,?)&quot;,(&#x27;南大通用&#x27;,&#x27;天津市海泰绿色产业基地&#x27;))</span><br><span class="line">    mycursor.execute(&quot;insert into company(coname,coaddr) values (?,?)&quot;,(&#x27;南大通用北京分公司&#x27;,&#x27;北京市朝阳区太阳宫&#x27;)) </span><br><span class="line">    mycursor.execute(&quot;update company set coaddr = ? where coid = 1&quot;,(&#x27;天津市普天创新园&#x27;,))</span><br><span class="line">    mycursor.execute(&quot;select * from company&quot;)</span><br><span class="line">    rows = mycursor.fetchall()</span><br><span class="line">    for i, (coid, coname, coaddr) in enumerate(rows):</span><br><span class="line">        print(&quot;公司ID: %d \t公司名称：%s\t公司地址: %s&quot; % (coid, str(coname), coaddr))</span><br><span class="line">    mycursor.close()</span><br><span class="line">    conn.close()</span><br><span class="line">    print(&quot;\nPython JayDeBeApi JDBC 测试程序结束运行.\n&quot;)</span><br><span class="line">    return render(req, &quot;blog/03.文章详情页面.html&quot;, &#123;&quot;id&quot;: id&#125;)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="迁移Mysql-Blog表数据到GBase8s"><a href="#迁移Mysql-Blog表数据到GBase8s" class="headerlink" title="迁移Mysql-Blog表数据到GBase8s"></a>迁移Mysql-Blog表数据到GBase8s</h2><p>​		见我之前的blog，手动迁移很快，就两步。</p>
<p><strong>Mysql导出数据</strong></p>
<p>mysql -uroot -pww1984830 myblog</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">SELECT * INTO OUTFILE &#x27;/tmp/result.text&#x27;</span><br><span class="line">FIELDS TERMINATED BY &#x27;|&#x27; OPTIONALLY ENCLOSED BY &#x27;&#x27;</span><br><span class="line">LINES TERMINATED BY &#x27;\n&#x27;</span><br><span class="line">FROM blog;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>GBase导入数据</strong></p>
<p>先用工具迁移表结构就可以了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#123; TABLE &quot;gbasedbt&quot;.blog row size = 3145 number of columns = 6 index size = 9 ccolnum = 0</span><br><span class="line"> commcol = id,title,content,categories,author,rq &#125;</span><br><span class="line"></span><br><span class="line">create table &quot;gbasedbt&quot;.blog </span><br><span class="line">  (</span><br><span class="line">    id serial not null ,</span><br><span class="line">    title varchar(1020),</span><br><span class="line">    content text,</span><br><span class="line">    categories varchar(1020),</span><br><span class="line">    author varchar(1020),</span><br><span class="line">    rq datetime year to fraction(5),</span><br><span class="line">    primary key (id) </span><br><span class="line">  ) extent size 16 next size 16 lock mode row;</span><br><span class="line"></span><br><span class="line">revoke all on &quot;gbasedbt&quot;.blog from &quot;public&quot; as &quot;gbasedbt&quot;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>接着直接导入数据即可：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">load from /tmp/result.text insert into blog;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="GBase使用CLOB字段的全文索引"><a href="#GBase使用CLOB字段的全文索引" class="headerlink" title="GBase使用CLOB字段的全文索引"></a>GBase使用CLOB字段的全文索引</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 导出MySQL的数据 （不用导出了，家目录已经有blog/unload数据了。）</span></span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">INTO</span> OUTFILE <span class="string">&#x27;/tmp/result.text&#x27;</span></span><br><span class="line">FIELDS TERMINATED <span class="keyword">BY</span> <span class="string">&#x27;|&#x27;</span> OPTIONALLY ENCLOSED <span class="keyword">BY</span> <span class="string">&#x27;&#x27;</span></span><br><span class="line">LINES TERMINATED <span class="keyword">BY</span> <span class="string">&#x27;\n&#x27;</span></span><br><span class="line"><span class="keyword">FROM</span> blog;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">-- 创建text字段表,并插入mysql导出的数据</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> blogtext(id serial <span class="keyword">not</span> <span class="keyword">null</span>,name <span class="type">varchar</span>(<span class="number">1024</span>),blog text, <span class="type">time</span>  datetime <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span> <span class="keyword">default</span> <span class="keyword">current</span> <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span>);</span><br><span class="line">load <span class="keyword">from</span> blog.unload <span class="keyword">insert</span> <span class="keyword">into</span> blogtext;</span><br><span class="line"><span class="comment">-- text字段不能作为查询条件</span></span><br><span class="line"><span class="operator">&gt;</span> <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> blogtext <span class="keyword">where</span>  blogtext.blog <span class="operator">=</span> <span class="string">&#x27;aaa&#x27;</span>;</span><br><span class="line">  <span class="number">615</span>: Blobs <span class="keyword">are</span> <span class="keyword">not</span> allowed <span class="keyword">in</span> this expression.</span><br><span class="line">Error <span class="keyword">in</span> line <span class="number">1</span></span><br><span class="line">Near <span class="type">character</span> position <span class="number">45</span></span><br><span class="line"><span class="operator">&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">-- 而varchar255和lvarchar32739都不够存储，所以只能用clob来存储，clob支持bts检索。</span></span><br><span class="line"><span class="comment">-- 创建clob表，并利用text的数导出，并插入clob中</span></span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> blog;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> blog(id serial <span class="keyword">not</span> <span class="keyword">null</span> <span class="keyword">primary</span> key,name <span class="type">varchar</span>(<span class="number">1024</span>),blog <span class="type">clob</span>, <span class="type">time</span>  datetime <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span> <span class="keyword">default</span> <span class="keyword">current</span> <span class="keyword">year</span> <span class="keyword">to</span> <span class="keyword">second</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> blog(name,blog) <span class="keyword">select</span> name,LOCOPY(blog) <span class="keyword">from</span> blogtext ;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">-- clob字段没有bts索引时也不能作为查询条件</span></span><br><span class="line"><span class="operator">&gt;</span> <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> blog <span class="keyword">where</span>  blog.blog <span class="operator">=</span> <span class="string">&#x27;aaa&#x27;</span>;</span><br><span class="line">(U0001) <span class="operator">-</span> blob_input: cannot <span class="keyword">convert</span> LO <span class="keyword">from</span> argument string</span><br><span class="line">Error <span class="keyword">in</span> line <span class="number">1</span></span><br><span class="line">Near <span class="type">character</span> position <span class="number">43</span></span><br><span class="line"><span class="operator">&gt;</span></span><br><span class="line"><span class="operator">&gt;</span> <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> blog <span class="keyword">where</span>  BTS_CONTAINS(blog.blog,<span class="string">&#x27;aaa&#x27;</span>);</span><br><span class="line">(BTS22) <span class="operator">-</span> bts error <span class="operator">-</span> bts_contains requires an index <span class="keyword">on</span> the <span class="keyword">search</span> <span class="keyword">column</span></span><br><span class="line">Error <span class="keyword">in</span> line <span class="number">1</span></span><br><span class="line">Near <span class="type">character</span> position <span class="number">55</span></span><br><span class="line"><span class="operator">&gt;</span></span><br><span class="line"><span class="comment">-- 创建bts索引</span></span><br><span class="line"><span class="keyword">create</span> index btsidx01 <span class="keyword">on</span> blog(blog bts_clob_ops) <span class="keyword">using</span> bts(analyzer<span class="operator">=</span>&quot;CJK&quot;);</span><br><span class="line"><span class="operator">&gt;</span> <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> blog <span class="keyword">where</span>  BTS_CONTAINS(blog.blog,<span class="string">&#x27;aaa&#x27;</span>);</span><br><span class="line"><span class="number">13</span> <span class="type">row</span>(s) retrieved.</span><br><span class="line">Elapsed <span class="type">time</span>: <span class="number">0.305</span> sec</span><br><span class="line"><span class="operator">&gt;</span></span><br><span class="line"><span class="comment">-- 完结。</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">-- 另外说明：BTS_CONTAINS好像不支持or连接</span></span><br><span class="line"><span class="operator">&gt;</span> <span class="keyword">select</span> id,name <span class="keyword">from</span> blog <span class="keyword">where</span> name <span class="keyword">like</span> <span class="string">&#x27;%欲壑难填%&#x27;</span> <span class="keyword">or</span> BTS_CONTAINS(blog.blog,<span class="string">&#x27;欲壑难填&#x27;</span>) ;</span><br><span class="line">(BTS22) <span class="operator">-</span> bts error <span class="operator">-</span> bts_contains requires an index <span class="keyword">on</span> the <span class="keyword">search</span> <span class="keyword">column</span></span><br><span class="line">Error <span class="keyword">in</span> line <span class="number">1</span></span><br><span class="line">Near <span class="type">character</span> position <span class="number">99</span></span><br><span class="line"><span class="operator">&gt;</span>  <span class="keyword">select</span> id,name <span class="keyword">from</span> blog <span class="keyword">where</span>  BTS_CONTAINS(blog.blog,<span class="string">&#x27;欲壑难填&#x27;</span>) ;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="我的博客数据库最终设计结果："><a href="#我的博客数据库最终设计结果：" class="headerlink" title="我的博客数据库最终设计结果："></a>我的博客数据库最终设计结果：</h2><p>说明：</p>
<ul>
<li><p>text不支持全文索引</p>
</li>
<li><p>clob在python端的’com.gbasedbt.jdbc.IfxCblob’对象我不会处理</p>
</li>
<li><p>clob在数据库端大于32767无法转string</p>
</li>
<li><p>关于表同步，如果不用业务双写，也可以用企业复制和触发器。</p>
</li>
</ul>
<p>最终设计结果：</p>
<ul>
<li>设计两张表：blogtext 和 blogclob</li>
<li>新增，修改(写部分)，删除  -&gt;  同时操作两张表。</li>
<li>查看，修改(读部分)              -&gt;  只操作blogtext表。</li>
<li>搜索                                       -&gt;  只操作blogclob表。</li>
</ul>
<h2 id="数据库端最终脚本："><a href="#数据库端最终脚本：" class="headerlink" title="数据库端最终脚本："></a>数据库端最终脚本：</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">初始化数据表： 1.1.1.3 gbasedbt家目录 g330实例 直接执行下面的脚本。</span></span><br><span class="line">cd </span><br><span class="line">dbaccess myblog &lt;&lt;!</span><br><span class="line">	drop table blogtext;</span><br><span class="line">	create table blogtext(id serial not null primary key,name varchar(1024),blog text, time  datetime year to second default current year to second);</span><br><span class="line">	load from blog.unload insert into blogtext;</span><br><span class="line">	</span><br><span class="line">	drop table blogclob;</span><br><span class="line">	create table blogclob(id serial not null primary key,name varchar(1024),blog clob, time  datetime year to second default current year to second);</span><br><span class="line">	insert into blogclob(id,name,blog,time) select id,name,LOCOPY(blog),time from blogtext ;</span><br><span class="line">	create index btsidx01 on blogclob(blog bts_clob_ops) using bts(analyzer=&quot;CJK&quot;);</span><br><span class="line">!</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="迁移gbase8s-从1-1-1-66到1-1-1-7"><a href="#迁移gbase8s-从1-1-1-66到1-1-1-7" class="headerlink" title="迁移gbase8s 从1.1.1.66到1.1.1.7"></a>迁移gbase8s 从1.1.1.66到1.1.1.7</h2><h3 id="备份表和数据库"><a href="#备份表和数据库" class="headerlink" title="备份表和数据库"></a>备份表和数据库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">su - gbasedbt</span><br><span class="line">mkdir -p ~/myblogBack ; cd ~/myblogBack</span><br><span class="line">dbexport myblog</span><br><span class="line">cd ..</span><br><span class="line">tar zcvf myblogBack.tar.gz myblogBack</span><br><span class="line">rm -fr myblogBack</span><br><span class="line">scp myblogBack.tar.gz 1.1.1.7:/home/gbasedbt/  #密码 GBase123</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="导入数据库"><a href="#导入数据库" class="headerlink" title="导入数据库"></a>导入数据库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">su - gbasedbt</span><br><span class="line">tar zxvf myblogBack.tar.gz</span><br><span class="line">cd myblogBack</span><br><span class="line">dbimport myblog -d datadbs01</span><br><span class="line">ontape -s -B myblog -t /dev/null</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">注意如果bts索引加不上去，需要手动添加一下bts类：  onmode -p +1 bts</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h2 id="数据库操作类-GBase8s-："><a href="#数据库操作类-GBase8s-：" class="headerlink" title="数据库操作类(GBase8s)："></a>数据库操作类(GBase8s)：</h2><p>自建模块：gbasedb.py</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> jaydebeapi</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">db</span>():</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self,ip,port,dbname,sername,user,pwd</span>):</span><br><span class="line">        self.conn = jaydebeapi.connect(<span class="string">&quot;com.gbasedbt.jdbc.Driver&quot;</span>,</span><br><span class="line">                                            <span class="string">f&quot;jdbc:gbasedbt-sqli://<span class="subst">&#123;ip&#125;</span>:<span class="subst">&#123;port&#125;</span>/<span class="subst">&#123;dbname&#125;</span>:GBASEDBTSERVER=<span class="subst">&#123;sername&#125;</span>;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=60&quot;</span>,</span><br><span class="line">                                            [user, pwd],</span><br><span class="line">                                            <span class="string">&quot;gbasedbtjdbc_3.3.0_2_36477d.jar&quot;</span></span><br><span class="line">                                            )</span><br><span class="line">        self.mycursor = self.conn.cursor()</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">select</span>(<span class="params">self,sql</span>):</span><br><span class="line">        self.mycursor.execute(sql)</span><br><span class="line">        rows = self.mycursor.fetchall()</span><br><span class="line">        <span class="keyword">return</span> rows</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">exec</span>(<span class="params">self,sql</span>):</span><br><span class="line">        self.mycursor.execute(sql)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">close</span>(<span class="params">self</span>):</span><br><span class="line">        self.mycursor.close()</span><br><span class="line">        self.conn.close()</span><br><span class="line">    </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>调用自建模块：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> gbasedb</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建连接</span></span><br><span class="line">db=gbasedb.db(<span class="string">&quot;1.1.1.66&quot;</span>,<span class="string">&quot;9083&quot;</span>,<span class="string">&quot;myblog&quot;</span>,<span class="string">&quot;g330&quot;</span>,<span class="string">&quot;gbasedbt&quot;</span>,<span class="string">&quot;GBase123&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 执行查询</span></span><br><span class="line">rows = db.select(<span class="string">&quot;select id,name,time from blogclob where id &lt; 5;&quot;</span>)</span><br><span class="line"><span class="keyword">for</span> k,(<span class="built_in">id</span>,name,sj) <span class="keyword">in</span> <span class="built_in">enumerate</span>(rows):</span><br><span class="line">    <span class="built_in">print</span>(<span class="built_in">id</span>,name,sj)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 执行写入</span></span><br><span class="line">db.<span class="built_in">exec</span>(<span class="string">&quot;delete from t3&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 断开连接</span></span><br><span class="line">db.close()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

















<h1 id="Python后续记录"><a href="#Python后续记录" class="headerlink" title="Python后续记录"></a>Python后续记录</h1><h2 id="python创建线程在后台运行"><a href="#python创建线程在后台运行" class="headerlink" title="python创建线程在后台运行"></a>python创建线程在后台运行</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> threading</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">print_b</span>():</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;aaa&quot;</span>)</span><br><span class="line">    time.sleep(<span class="number">5</span>)</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;bbb&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    thread = threading.Thread(target=print_b, args=())</span><br><span class="line">    thread.start()</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;ccc&quot;</span>)</span><br></pre></td></tr></table></figure>







<h1 id="Golang更适合跑在数据库端"><a href="#Golang更适合跑在数据库端" class="headerlink" title="Golang更适合跑在数据库端"></a>Golang更适合跑在数据库端</h1><ul>
<li><p>信息收集<br>1. </p>
</li>
<li><p>问题发现</p>
<ol>
<li><p>性能问题</p>
<ul>
<li>硬件上限（tps&#x2F;吞吐）</li>
<li>软件</li>
</ul>
</li>
<li><p>通断问题</p>
</li>
</ol>
</li>
</ul>
<h1 id="GBase8s答疑随记"><a href="#GBase8s答疑随记" class="headerlink" title="GBase8s答疑随记"></a>GBase8s答疑随记</h1><h2 id="concat合并字符串"><a href="#concat合并字符串" class="headerlink" title="concat合并字符串"></a>concat合并字符串</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator">&gt;</span> <span class="keyword">select</span> concat(name,name) <span class="keyword">from</span> t1;</span><br><span class="line">(expression)</span><br><span class="line">aa       aa</span><br><span class="line"><span class="number">1</span> <span class="type">row</span>(s) retrieved.</span><br><span class="line">Elapsed <span class="type">time</span>: <span class="number">0.001</span> sec</span><br><span class="line"><span class="operator">&gt;</span></span><br><span class="line"></span><br><span class="line">工作中遇到的一个问题，一张表中分别存有省份和市区两个字段，即province和locationname，现在有一个需求，一个输入框即可以输入省份又可以输入地市查询。</span><br><span class="line">这时候可以使用concat函数，但是由于concat函数中的字段其中有一个为<span class="keyword">null</span>，则会返回<span class="keyword">null</span>，如果是mysql数据库，就可以用ifnull函数。informix数据库只有用nvl函数，具体语句如下：</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">column</span> <span class="keyword">from</span> <span class="keyword">table</span> <span class="keyword">where</span> concat(nvl(column_1,&quot;&quot;),nvl(column_2,&quot;&quot;)) <span class="keyword">like</span> “<span class="operator">%</span>param<span class="operator">%</span>”.</span><br><span class="line">此时即使一个字段中的值为空，照样可以通过模糊查询查出。</span><br></pre></td></tr></table></figure>

















 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/bootstrap/" rel="tag">bootstrap</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css/" rel="tag">css</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/html/" rel="tag">html</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/javascripts/" rel="tag">javascripts</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%9F%BA%E7%A1%80/" rel="tag">基础</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-GBase8s测试BLOB和CLOB"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/09/GBase8s%E6%B5%8B%E8%AF%95BLOB%E5%92%8CCLOB/"
    >GBase8s测试BLOB和CLOB</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/09/GBase8s%E6%B5%8B%E8%AF%95BLOB%E5%92%8CCLOB/" class="article-date">
  <time datetime="2023-05-09T13:44:33.000Z" itemprop="datePublished">2023-05-09</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h3 id="建表"><a href="#建表" class="headerlink" title="建表"></a>建表</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE t_smart_objects ( id_num int, picture blob, felony clob )PUT picture in(sbspace01);</span><br></pre></td></tr></table></figure>

<h3 id="插入一行数据"><a href="#插入一行数据" class="headerlink" title="插入一行数据"></a>插入一行数据</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">INSERT INTO t_smart_objects VALUES(1,FILETOBLOB(&#x27;/tmp/aaa.jpg&#x27;,&#x27;client&#x27;),filetoclob(&#x27;/tmp/aaa1.txt&#x27;,&#x27;client&#x27;));</span><br><span class="line">INSERT INTO t_smart_objects VALUES(2,FILETOBLOB(&#x27;/tmp/aaa.jpg&#x27;,&#x27;client&#x27;),filetoclob(&#x27;/tmp/aaa2.txt&#x27;,&#x27;client&#x27;));</span><br><span class="line">INSERT INTO t_smart_objects VALUES(3,FILETOBLOB(&#x27;/tmp/aaa.jpg&#x27;,&#x27;client&#x27;),filetoclob(&#x27;/tmp/aaa3.txt&#x27;,&#x27;client&#x27;));</span><br></pre></td></tr></table></figure>

<h3 id="用python程序读取这个图片内容，和这个文件内容"><a href="#用python程序读取这个图片内容，和这个文件内容" class="headerlink" title="用python程序读取这个图片内容，和这个文件内容"></a>用python程序读取这个图片内容，和这个文件内容</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">import jaydebeapi</span><br><span class="line"></span><br><span class="line">class gbasedb():</span><br><span class="line">    def __init__(self,ip,port,dbname,sername,user,pwd):</span><br><span class="line">        self.conn = jaydebeapi.connect(&quot;com.gbasedbt.jdbc.Driver&quot;,</span><br><span class="line">                                            f&quot;jdbc:gbasedbt-sqli://&#123;ip&#125;:&#123;port&#125;/&#123;dbname&#125;:GBASEDBTSERVER=&#123;sername&#125;;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=60&quot;,</span><br><span class="line">                                            [user, pwd],</span><br><span class="line">                                            &quot;gbasedbtjdbc_3.3.0_2_36477d.jar&quot;</span><br><span class="line">                                            )</span><br><span class="line">        self.mycursor = self.conn.cursor()</span><br><span class="line">    </span><br><span class="line">    def select(self,sql):</span><br><span class="line">        self.mycursor.execute(sql)</span><br><span class="line">        rows = self.mycursor.fetchall()</span><br><span class="line">        return rows</span><br><span class="line"></span><br><span class="line">    def exec(self,sql):</span><br><span class="line">        self.mycursor.execute(sql)</span><br><span class="line"></span><br><span class="line">    def close(self):</span><br><span class="line">        self.mycursor.close()</span><br><span class="line">        self.conn.close()</span><br><span class="line">    </span><br><span class="line"># 创建连接</span><br><span class="line">db=gbasedb(&quot;1.1.1.7&quot;,&quot;9083&quot;,&quot;testdb&quot;,&quot;g330&quot;,&quot;gbasedbt&quot;,&quot;GBase123&quot;)</span><br><span class="line"></span><br><span class="line"># 执行查询</span><br><span class="line">rows = db.select(&quot;select id_num,picture,felony from t_smart_objects ;&quot;)</span><br><span class="line">for k,(id,b,c) in enumerate(rows):</span><br><span class="line">    print(id,b,c)</span><br><span class="line"></span><br><span class="line"># 断开连接</span><br><span class="line">db.close()</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="可以看到python能读取到，但是不能直接打印"><a href="#可以看到python能读取到，但是不能直接打印" class="headerlink" title="可以看到python能读取到，但是不能直接打印"></a>可以看到python能读取到，但是不能直接打印</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">PS D:\soft\src\Python3\Django\project01\app01\database\智能大对象操作测试&gt; python.exe .\read_blob_clob.py</span><br><span class="line">1 com.gbasedbt.jdbc.IfxBblob@5f205aa com.gbasedbt.jdbc.IfxCblob@6d86b085</span><br><span class="line">PS D:\soft\src\Python3\Django\project01\app01\database\智能大对象操作测试&gt;</span><br></pre></td></tr></table></figure>

<h3 id="吧这两个对象存入文件？"><a href="#吧这两个对象存入文件？" class="headerlink" title="吧这两个对象存入文件？"></a>吧这两个对象存入文件？</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#正常，不报错</span><br><span class="line">fo = open(&quot;aaa.txt&quot;,&quot;w&quot;)</span><br><span class="line">fo.write(str(id))</span><br><span class="line">fo.close()</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#报错，TypeError: write() argument must be str, not com.gbasedbt.jdbc.IfxCBblob</span><br><span class="line">fo = open(&quot;aaa.txt&quot;,&quot;w&quot;)</span><br><span class="line">fo.write(b)</span><br><span class="line">fo.close()</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#报错，TypeError: write() argument must be str, not com.gbasedbt.jdbc.IfxCblob</span><br><span class="line">fo = open(&quot;aaa.txt&quot;,&quot;w&quot;)</span><br><span class="line">fo.write(c)</span><br><span class="line">fo.close()</span><br></pre></td></tr></table></figure>

<h3 id="这样存储BLOB和CLOB到文件"><a href="#这样存储BLOB和CLOB到文件" class="headerlink" title="这样存储BLOB和CLOB到文件"></a>这样存储BLOB和CLOB到文件</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">import jaydebeapi</span><br><span class="line"></span><br><span class="line">class gbasedb():</span><br><span class="line">    def __init__(self,ip,port,dbname,sername,user,pwd):</span><br><span class="line">        self.conn = jaydebeapi.connect(&quot;com.gbasedbt.jdbc.Driver&quot;,</span><br><span class="line">                                            f&quot;jdbc:gbasedbt-sqli://&#123;ip&#125;:&#123;port&#125;/&#123;dbname&#125;:GBASEDBTSERVER=&#123;sername&#125;;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=60&quot;,</span><br><span class="line">                                            [user, pwd],</span><br><span class="line">                                            &quot;gbasedbtjdbc_3.3.0_2_36477d.jar&quot;</span><br><span class="line">                                            )</span><br><span class="line">        self.mycursor = self.conn.cursor()</span><br><span class="line">    </span><br><span class="line">    def select(self,sql):</span><br><span class="line">        self.mycursor.execute(sql)</span><br><span class="line">        rows = self.mycursor.fetchall()</span><br><span class="line">        return rows</span><br><span class="line"></span><br><span class="line">    def exec(self,sql):</span><br><span class="line">        self.mycursor.execute(sql)</span><br><span class="line"></span><br><span class="line">    def close(self):</span><br><span class="line">        self.mycursor.close()</span><br><span class="line">        self.conn.close()</span><br><span class="line">    </span><br><span class="line"># 创建连接</span><br><span class="line">db=gbasedb(&quot;1.1.1.7&quot;,&quot;9083&quot;,&quot;testdb&quot;,&quot;g330&quot;,&quot;gbasedbt&quot;,&quot;GBase123&quot;)</span><br><span class="line"></span><br><span class="line"># 执行查询</span><br><span class="line">rows = db.select(&quot;select id_num,lotofile(picture,&#x27;blob&#x27;,&#x27;client&#x27;),lotofile(felony ,&#x27;clob&#x27;,&#x27;client&#x27;) from t_smart_objects ;&quot;)</span><br><span class="line">fo = open(&quot;aaa.txt&quot;,&quot;w&quot;)</span><br><span class="line">fo.close()</span><br><span class="line">for k,(id,b,c) in enumerate(rows):</span><br><span class="line">    print(id,b,c)</span><br><span class="line">    fo = open(&quot;aaa.txt&quot;,&quot;a&quot;)</span><br><span class="line">    fo.write(str(id)+&quot;|&quot;+b+&quot;|&quot;+c+&quot;\n&quot;)</span><br><span class="line">    fo.close()</span><br><span class="line"># 断开连接</span><br><span class="line">db.close()</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>上面程序的运行结果如下，BLOB和CLOB都存存储到了文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">PS D:\soft\src\Python3\Django\project01\app01\database\智能大对象操作测试&gt; python.exe .\read_blob_clob.py</span><br><span class="line">1 blob.1589924831 clob.1644716430</span><br><span class="line">1 blob.749102841 clob.1323486100</span><br><span class="line">2 blob.1527510893 clob.1148413881</span><br><span class="line">3 blob.1450167526 clob.1972740189</span><br><span class="line">PS D:\soft\src\Python3\Django\project01\app01\database\智能大对象操作测试&gt; cat aaa.txt</span><br><span class="line">1|blob.1589924831|clob.1644716430</span><br><span class="line">1|blob.749102841|clob.1323486100</span><br><span class="line">2|blob.1527510893|clob.1148413881</span><br><span class="line">3|blob.1450167526|clob.1972740189</span><br></pre></td></tr></table></figure>

<h3 id="数据库使用BLOB和CLOB小结"><a href="#数据库使用BLOB和CLOB小结" class="headerlink" title="数据库使用BLOB和CLOB小结"></a>数据库使用BLOB和CLOB小结</h3><ul>
<li>使用LOTOFILE下载BLOB和CLOB到本地</li>
<li>使用FILETOBLOB上传图片到数据库</li>
<li>使用FILETOCLOB上传文本到数据库</li>
<li>LOCOP() 复制BLOB或者CLOB数据到另外一个BLOB或者CLOB列中</li>
</ul>
<h3 id="Python中读取图片BLOB到字节串，读取文档CLOB到字节串"><a href="#Python中读取图片BLOB到字节串，读取文档CLOB到字节串" class="headerlink" title="Python中读取图片BLOB到字节串，读取文档CLOB到字节串"></a>Python中读取图片BLOB到字节串，读取文档CLOB到字节串</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">open_icon = open(&quot;blob.1589924831&quot;,&quot;rb&quot;) </span><br><span class="line">s = open_icon.read()</span><br><span class="line">open_icon.close() </span><br><span class="line"></span><br><span class="line">print(&quot;图片已经读入字符串s，s的类型是：&quot;,type(s))</span><br><span class="line"></span><br><span class="line">picture = open(&quot;blob.jpg&quot;,&quot;wb&quot;) </span><br><span class="line">picture.write(s) </span><br><span class="line">picture.close()</span><br><span class="line"></span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%A4%A7%E5%AF%B9%E8%B1%A1/" rel="tag">大对象</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%B5%8B%E8%AF%95%E7%94%A8%E4%BE%8B/" rel="tag">测试用例</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-GBase8s存储过程游标传递（指针传递）外用"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/09/GBase8s%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B%E6%B8%B8%E6%A0%87%E4%BC%A0%E9%80%92%EF%BC%88%E6%8C%87%E9%92%88%E4%BC%A0%E9%80%92%EF%BC%89%E5%A4%96%E7%94%A8/"
    >GBase8s存储过程游标传递（指针传递）外用</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/09/GBase8s%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B%E6%B8%B8%E6%A0%87%E4%BC%A0%E9%80%92%EF%BC%88%E6%8C%87%E9%92%88%E4%BC%A0%E9%80%92%EF%BC%89%E5%A4%96%E7%94%A8/" class="article-date">
  <time datetime="2023-05-09T13:39:47.000Z" itemprop="datePublished">2023-05-09</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h3 id="表"><a href="#表" class="headerlink" title="表"></a>表</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> &quot;gbasedbt&quot;.tab1</span><br><span class="line">(</span><br><span class="line">    c1 <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    c2 <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    c3 <span class="type">varchar</span>(<span class="number">255</span>)</span><br><span class="line">) extent size <span class="number">16</span> next size <span class="number">32</span> lock mode <span class="type">row</span>;</span><br><span class="line"><span class="keyword">revoke</span> <span class="keyword">all</span> <span class="keyword">on</span> &quot;gbasedbt&quot;.tab1 <span class="keyword">from</span> &quot;public&quot; <span class="keyword">as</span> &quot;gbasedbt&quot;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> &quot;gbasedbt&quot;.tab2</span><br><span class="line">(</span><br><span class="line">    b1 <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    b2 <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    b3 <span class="type">varchar</span>(<span class="number">255</span>)</span><br><span class="line">) extent size <span class="number">16</span> next size <span class="number">32</span> lock mode <span class="type">row</span>;</span><br><span class="line"><span class="keyword">revoke</span> <span class="keyword">all</span> <span class="keyword">on</span> &quot;gbasedbt&quot;.tab2 <span class="keyword">from</span> &quot;public&quot; <span class="keyword">as</span> &quot;gbasedbt&quot;;</span><br></pre></td></tr></table></figure>




<h3 id="指针传递"><a href="#指针传递" class="headerlink" title="指针传递"></a>指针传递</h3><pre><code>下面两个存储过程合在一起的作用，就是指针传递。在一个存储存储过程中赋值的游标，在其他地方页可以loop遍历。
</code></pre>
<h3 id="存储过程：p01"><a href="#存储过程：p01" class="headerlink" title="存储过程：p01"></a>存储过程：p01</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--      3个值1个游标入参，（1个游标即一个指针）</span></span><br><span class="line"><span class="comment">--      这个过程的作用：给游标赋值</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">procedure</span> &quot;gbasedbt&quot;.p01(</span><br><span class="line">    c1   <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    c2   <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    c3   <span class="type">varchar</span>(<span class="number">255</span>),</span><br><span class="line">    <span class="keyword">Out</span>  o4  SYS_REFCURSOR)</span><br><span class="line">    <span class="keyword">define</span> str <span class="type">varchar</span>(<span class="number">255</span>);</span><br><span class="line">    let str<span class="operator">=</span><span class="string">&#x27;&#x27;</span>;</span><br><span class="line">    <span class="keyword">Open</span> o4 <span class="keyword">For</span> &quot;Select c1 From tab1 t Where t.c1 = ? And t.c2 = ? And t.c3 = ?&quot; <span class="keyword">using</span> c1,c2,c3;</span><br><span class="line">    <span class="comment">--loop</span></span><br><span class="line">    <span class="comment">--    fetch o4 into str;</span></span><br><span class="line">    <span class="comment">--    exit when SQLCODE == 100;</span></span><br><span class="line">    <span class="comment">--    insert into tab2(b2) values(str);</span></span><br><span class="line">    <span class="comment">--end loop;</span></span><br><span class="line"><span class="keyword">end</span> <span class="keyword">procedure</span></span><br><span class="line">;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="存储过程：test"><a href="#存储过程：test" class="headerlink" title="存储过程：test"></a>存储过程：test</h3><p>–      这个过程的作用：调用其他存储过程，获取游标，并遍历游标。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">procedure</span> &quot;gbasedbt&quot;.test()</span><br><span class="line">    <span class="keyword">define</span> out4 SYS_REFCURSOR;</span><br><span class="line">    <span class="keyword">define</span> str <span class="type">varchar</span>(<span class="number">255</span>);</span><br><span class="line">    <span class="keyword">SET</span> DEBUG FILE <span class="keyword">TO</span> <span class="string">&#x27;/tmp/test3.trace&#x27;</span>;</span><br><span class="line">        TRACE <span class="keyword">ON</span>;</span><br><span class="line">    let  out4<span class="operator">=</span> <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">begin</span></span><br><span class="line">        <span class="keyword">call</span> p01(<span class="string">&#x27;aaa&#x27;</span>,<span class="string">&#x27;bbb&#x27;</span>,<span class="string">&#x27;ccc&#x27;</span>,out4);</span><br><span class="line">    <span class="keyword">END</span></span><br><span class="line">    let str <span class="operator">=</span><span class="string">&#x27;&#x27;</span>;</span><br><span class="line">    loop</span><br><span class="line">        <span class="keyword">fetch</span> out4 <span class="keyword">into</span> str;</span><br><span class="line">        exit <span class="keyword">when</span> SQLCODE <span class="operator">=</span><span class="operator">=</span> <span class="number">100</span>;</span><br><span class="line">        <span class="keyword">insert</span> <span class="keyword">into</span> tab2(b3) <span class="keyword">values</span>(str);</span><br><span class="line">    <span class="keyword">end</span> loop;</span><br><span class="line"><span class="keyword">end</span> <span class="keyword">procedure</span></span><br><span class="line">;</span><br></pre></td></tr></table></figure>

<h3 id="映射xml文件"><a href="#映射xml文件" class="headerlink" title="映射xml文件"></a>映射xml文件</h3><p>D:\soft\src\Java\demoSpringBootMybatisDruid\src\main\resources\mybatis\mapper\ProcedureTest.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span> ?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">mapper</span></span></span><br><span class="line"><span class="meta">        <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">&quot;com.trey.mapper.ProcedureTestMapper&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">&quot;exeProcedure&quot;</span> <span class="attr">resultType</span>=<span class="string">&quot;Test&quot;</span>&gt;</span></span><br><span class="line">        call test();</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="映射"><a href="#映射" class="headerlink" title="映射"></a>映射</h3><p>D:\soft\src\Java\demoSpringBootMybatisDruid\src\main\java\com\trey\mapper\ProcedureTestMapper.java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.mapper;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.trey.pojo.Test;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.annotations.Mapper;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Repository;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Mapper</span></span><br><span class="line"><span class="meta">@Repository</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">ProcedureTestMapper</span> &#123;</span><br><span class="line">    List&lt;Test&gt; <span class="title function_">exeProcedure</span><span class="params">()</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="控制器（路由）"><a href="#控制器（路由）" class="headerlink" title="控制器（路由）"></a>控制器（路由）</h3><p>D:\soft\src\Java\demoSpringBootMybatisDruid\src\main\java\com\trey\controller\ProcedureTest.java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.trey.controller;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.trey.mapper.ProcedureTestMapper;</span><br><span class="line"><span class="keyword">import</span> com.trey.pojo.Test;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.GetMapping;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RestController;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ProcedureTest</span> &#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> ProcedureTestMapper procedureTestMapper;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@GetMapping(&quot;/exeProcedure&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> List&lt;Test&gt; <span class="title function_">exeProcedure</span><span class="params">()</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> procedureTestMapper.exeProcedure();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/GBase8s/" rel="tag">GBase8s</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B/" rel="tag">存储过程</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%8C%87%E9%92%88%E6%B8%B8%E6%A0%87/" rel="tag">指针游标</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-multipath的输出脚本解读多路径输出结果"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/09/multipath%E7%9A%84%E8%BE%93%E5%87%BA%E8%84%9A%E6%9C%AC%E8%A7%A3%E8%AF%BB%E5%A4%9A%E8%B7%AF%E5%BE%84%E8%BE%93%E5%87%BA%E7%BB%93%E6%9E%9C/"
    >multipath的输出脚本解读多路径输出结果</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/09/multipath%E7%9A%84%E8%BE%93%E5%87%BA%E8%84%9A%E6%9C%AC%E8%A7%A3%E8%AF%BB%E5%A4%9A%E8%B7%AF%E5%BE%84%E8%BE%93%E5%87%BA%E7%BB%93%E6%9E%9C/" class="article-date">
  <time datetime="2023-05-09T13:35:43.000Z" itemprop="datePublished">2023-05-09</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Shell/">Shell</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h3 id="脚本解读多路径输出结果"><a href="#脚本解读多路径输出结果" class="headerlink" title="脚本解读多路径输出结果"></a>脚本解读多路径输出结果</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/bash</span></span><br><span class="line"></span><br><span class="line">oneDiskStatus()&#123;</span><br><span class="line">        awk &#x27;</span><br><span class="line">        BEGIN &#123;</span><br><span class="line">                printf(&quot;%35s%20s%10s%10s%10s%10s%10s%10s%10s%10s&quot;,&quot;DiskNAME&quot;,&quot;DisKStatus&quot;,&quot;PATH1&quot;,&quot;PATH2&quot;,&quot;PATH3&quot;,&quot;PATH4&quot;,&quot;PATH5&quot;,&quot;PATH6&quot;,&quot;PATH7&quot;,&quot;PATH8&quot;)</span><br><span class="line">        &#125;</span><br><span class="line">        &#123;</span><br><span class="line">                if($1~/36/)&#123;</span><br><span class="line">                        printf(&quot;\n%35s&quot;,$1)</span><br><span class="line">                &#125;</span><br><span class="line">                if($1~/size/)&#123;</span><br><span class="line">                &#125;</span><br><span class="line">                if($2~/policy/)&#123;</span><br><span class="line">                        printf(&quot;%20s&quot;,$NF)</span><br><span class="line">                &#125;</span><br><span class="line">                if($2~/:/)&#123;</span><br><span class="line">                        printf(&quot;%10s&quot;,$5)</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">        &#125; END &#123;</span><br><span class="line">                print &quot;&quot;</span><br><span class="line">        &#125;&#x27;  multipath.log</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">oneDiskStatus</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="脚本执行结果"><a href="#脚本执行结果" class="headerlink" title="脚本执行结果"></a>脚本执行结果</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@wei07 mult]# sh b.sh</span><br><span class="line">                           DiskNAME          DisKStatus     PATH1     PATH2     PATH3     PATH4     PATH5     PATH6     PATH7     PATH8</span><br><span class="line">  36f033e51007dfabf4aa20acc000000a5       status=active    active    active    active    active    active    active    active    active</span><br><span class="line">  36f033e51007dfabf4aa20acc00000099       status=active    active    active    active    active    active    active    active    active</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h3 id="multipath-ll-的输出示例"><a href="#multipath-ll-的输出示例" class="headerlink" title="multipath -ll 的输出示例"></a>multipath -ll 的输出示例</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[root@wei07 mult]# head -20 multipath.log</span><br><span class="line">36f033e51007dfabf4aa20acc000000a5 dm-79 HUAWEI,XSG1</span><br><span class="line">size=1.0T features=&#x27;1 queue_if_no_path&#x27; hwhandler=&#x27;0&#x27; wp=rw</span><br><span class="line">`-+- policy=&#x27;service-time 0&#x27; prio=1 status=active</span><br><span class="line">  |- 14:0:0:31 sdhw 134:96  active ready running</span><br><span class="line">  |- 9:0:0:31  sdij 135:48  active ready running</span><br><span class="line">  |- 11:0:0:31 sdif 134:240 active ready running</span><br><span class="line">  |- 16:0:0:31 sdhr 134:16  active ready running</span><br><span class="line">  |- 12:0:0:31 sdiy 8:288   active ready running</span><br><span class="line">  |- 13:0:0:31 sdik 135:64  active ready running</span><br><span class="line">  |- 15:0:0:31 sdir 135:176 active ready running</span><br><span class="line">  `- 10:0:0:31 sdjw 65:416  active ready running</span><br><span class="line">36f033e51007dfabf4aa20acc00000099 dm-57 HUAWEI,XSG1</span><br><span class="line">size=1.0T features=&#x27;1 queue_if_no_path&#x27; hwhandler=&#x27;0&#x27; wp=rw</span><br><span class="line">`-+- policy=&#x27;service-time 0&#x27; prio=1 status=active</span><br><span class="line">  |- 16:0:0:19 sddt 71:176  active ready running</span><br><span class="line">  |- 11:0:0:19 sdei 128:160 active ready running</span><br><span class="line">  |- 13:0:0:19 sdek 128:192 active ready running</span><br><span class="line">  |- 14:0:0:19 sdeg 128:128 active ready running</span><br><span class="line">  |- 12:0:0:19 sdev 129:112 active ready running</span><br><span class="line">  |- 9:0:0:19  sdfc 129:224 active ready running</span><br><span class="line">[root@wei07 mult]#</span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/multipath/" rel="tag">multipath</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-clob智能大对象插入慢问题"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/05/09/clob%E6%99%BA%E8%83%BD%E5%A4%A7%E5%AF%B9%E8%B1%A1%E6%8F%92%E5%85%A5%E6%85%A2%E9%97%AE%E9%A2%98/"
    >clob智能大对象插入慢问题</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/05/09/clob%E6%99%BA%E8%83%BD%E5%A4%A7%E5%AF%B9%E8%B1%A1%E6%8F%92%E5%85%A5%E6%85%A2%E9%97%AE%E9%A2%98/" class="article-date">
  <time datetime="2023-05-09T13:31:50.000Z" itemprop="datePublished">2023-05-09</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">工单：（readmaine 5118）</span><br><span class="line"></span><br><span class="line">基础理论：</span><br><span class="line">	1、GBase8s里面clob和blob智能大对象的存储是：</span><br><span class="line">		1.1 数据行存储在表的extentd区段里面，一个槽位里面存储了普通数据库，和智能大对象数据的指针概要。</span><br><span class="line">		1.2 这个存储模式，在insert包含大对象的行的时候，就会比普通数据多出好多步骤。</span><br><span class="line"></span><br><span class="line">测试方向和测试结果：</span><br><span class="line">	1、用shell测试了带clob字段insert，1000条60秒完成。</span><br><span class="line">	2、用shell测试了不带clob字段insert，1000条4秒完成。</span><br><span class="line">	3、用java测试了带clob字段insert，1000条163秒完成。</span><br><span class="line">	4、用java测试了带clob字段insert，5个线程并发，1000条112秒完成。</span><br><span class="line">	5、用java测试了不带clob字段insert，1000条6秒完成。</span><br><span class="line">	（java代码见：D:\soft\05.工作记录\05.L2内部\工作事项记录\有CLOB字段的表的插入测试.rar）</span><br><span class="line">	</span><br><span class="line">测试小结：</span><br><span class="line">	1、带clob字段的insert没有办法变块，这是基础结构决定的。</span><br><span class="line">	2、可以考虑用text代替智能大对象，缺点是text不能全文索引。</span><br><span class="line">	</span><br><span class="line">业务优化建议：</span><br><span class="line">	1、有大量的大对象的话，建议用mongodb这样的文件存储的数据库。</span><br><span class="line">	2、GBase8s是一个稳定可靠高效的关系型数据库，支撑着金融行业保险行业高效的业务系统。</span><br></pre></td></tr></table></figure>

 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%A4%A7%E5%AF%B9%E8%B1%A1/" rel="tag">大对象</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%8F%92%E5%85%A5%E6%85%A2/" rel="tag">插入慢</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%B5%8B%E8%AF%95%E7%94%A8%E4%BE%8B/" rel="tag">测试用例</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-HDR宕机分析和目前推断"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/04/27/HDR%E5%AE%95%E6%9C%BA%E5%88%86%E6%9E%90%E5%92%8C%E7%9B%AE%E5%89%8D%E6%8E%A8%E6%96%AD/"
    >HDR宕机分析和目前推断</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/04/27/HDR%E5%AE%95%E6%9C%BA%E5%88%86%E6%9E%90%E5%92%8C%E7%9B%AE%E5%89%8D%E6%8E%A8%E6%96%AD/" class="article-date">
  <time datetime="2023-04-27T08:33:47.000Z" itemprop="datePublished">2023-04-27</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="onlog分析"><a href="#onlog分析" class="headerlink" title="onlog分析"></a>onlog分析</h2><h5 id="02-50-02-创建了表-xrc-callstas-发起"><a href="#02-50-02-创建了表-xrc-callstas-发起" class="headerlink" title="02:50:02 创建了表 xrc_callstas 发起"></a>02:50:02 创建了表 xrc_callstas 发起</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">626a30c  56   BEGIN    144      879 0        04/27/2023 02:50:02 33557870 gbasedbt</span><br><span class="line">626a344  392  BLDCL    144      0  626a30c  6001dc 2048 2048 1536 0 xrc_callstas</span><br><span class="line">626a4cc  132  PTCOLUMN 144      0  626a344  6001dc   7</span><br><span class="line">626a550  52   CHALLOC  144      0  626a4cc  00006:0003195008 800</span><br><span class="line">626a584  56   PTEXTEND 144      0  626a550  6001dc   2047     00006:0003195008</span><br><span class="line">626a5bc  392  BLDCL    144      0  626a584  60022a 28 28 1536 0 idx_xrc_callstas</span><br><span class="line"></span><br><span class="line">addr     len  type     xid      id link</span><br><span class="line">626a744  52   CHALLOC  144      0  626a5bc  00006:0000197703 1c</span><br><span class="line">626a778  56   PTEXTEND 144      0  626a744  60022a   27       00006:0000197703</span><br><span class="line">626a7b0  192  CINDEX   144      0  626a778  60022a   1</span><br><span class="line">626b08c  52   PNLOCKID 144      0  626a7b0  6001dc   6001dc   60021a</span><br><span class="line">626b0c0  52   PNLOCKID 144      0  626b08c  60022a   60022a   60021a</span><br><span class="line">626b0f4  360  HDELETE  144      0  626b0c0  60001a   17302    295</span><br><span class="line">626b25c  72   DELITEM  144      0  626b0f4  60001a   60001a   17302    219   1     12</span><br><span class="line">626b2a4  140  PBDELETE 144      0  626b25c  60001a   12001    77       ffffffff</span><br><span class="line">626b330  532  PBDELETE 144      0  626b2a4  60001a   17401    470      ffffffff</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="02-50-02-创建表-xrc-callstas-提交"><a href="#02-50-02-创建表-xrc-callstas-提交" class="headerlink" title="02:50:02 创建表 xrc_callstas 提交"></a>02:50:02 创建表 xrc_callstas 提交</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">addr     len  type     xid      id link</span><br><span class="line">628d750  88   ADDITEM  144      0  628d5e0  60001a   60001a   fa01     219   1     27</span><br><span class="line">628d7a8  200  HUPBEF   144      0  628d750  600002   1504     135</span><br><span class="line">628e08c  200  HUPAFT   144      0  628d7a8  600002   1504     135</span><br><span class="line">628e154  48   UNIQID   144      0  628e08c  1000d2   5250</span><br><span class="line">628e184  88   HINSERT  144      0  628e154  1000d2   201      22</span><br><span class="line">628e1dc  72   ADDITEM  144      0  628e184  1000d2   1000d2   201      1     1     12</span><br><span class="line">628e224  80   HINSERT  144      0  628e1dc  1000d3   201      16</span><br><span class="line">628e274  68   ADDITEM  144      0  628e224  1000d3   1000d3   201      1     1     6</span><br><span class="line">628e2b8  80   HINSERT  144      0  628e274  1000d3   202      16</span><br><span class="line">628e308  68   ADDITEM  144      0  628e2b8  1000d3   1000d3   202      1     1     6</span><br><span class="line">628e34c  56   COMMIT   144      0  628e308  04/27/2023 02:50:02</span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h5 id="03-35-01-rename-table-所在事务的-发起"><a href="#03-35-01-rename-table-所在事务的-发起" class="headerlink" title="03:35:01 rename table 所在事务的 发起"></a>03:35:01 rename table 所在事务的 发起</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">65ea060  56   BEGIN    257      879 0        04/27/2023 03:35:01 33565257 gbasedbt</span><br><span class="line">65ea098  360  HDELETE  257      0  65ea060  60001a   e802     295</span><br><span class="line">65ea200  72   DELITEM  257      0  65ea098  60001a   60001a   e802     219   1     12</span><br><span class="line">65ea248  140  PBDELETE 257      0  65ea200  60001a   12001    77       ffffffff</span><br><span class="line">65ea2d4  532  PBDELETE 257      0  65ea248  60001a   e902     470      ffffffff</span><br><span class="line">65ea4e8  864  PBDELETE 257      0  65ea2d4  60001a   e901     801      ffffffff</span><br><span class="line">65eb064  360  HDELETE  257      0  65ea4e8  60001a   e803     295</span><br><span class="line">65eb1cc  72   DELITEM  257      0  65eb064  60001a   60001a   e803     219   1     12</span><br><span class="line"></span><br><span class="line">addr     len  type     xid      id link</span><br><span class="line">65eb214  140  PBDELETE 257      0  65eb1cc  60001a   12002    77       ffffffff</span><br><span class="line">65eb2a0  532  PBDELETE 257      0  65eb214  60001a   ea01     470      ffffffff</span><br><span class="line">65eb4b4  360  HDELETE  257      0  65eb2a0  60001a   e804     295</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h5 id="03-35-01-rename-table-的发起点"><a href="#03-35-01-rename-table-的发起点" class="headerlink" title="03:35:01 rename table 的发起点"></a>03:35:01 rename table 的发起点</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">65ff6b4  692  PTRENAME 257      0  65ff654    60021a xrc_callstas xrc_callstasp2023011700</span><br><span class="line">6600184  52   PNLOCKID 257      0  65ff6b4  600257   60021a   600257</span><br><span class="line">66001b8  52   PNLOCKID 257      0  6600184  600185   60021a   600257</span><br><span class="line">66001ec  52   PNLOCKID 257      0  66001b8  6001f0   60021a   600257</span><br><span class="line">6600220  52   PNLOCKID 257      0  66001ec  6000d9   60021a   600257</span><br><span class="line"></span><br><span class="line">addr     len  type     xid      id link</span><br><span class="line">6600254  52   PNLOCKID 257      0  6600220  600178   60021a   600257</span><br><span class="line">6600288  52   PNLOCKID 257      0  6600254  6001f2   60021a   600257</span><br><span class="line">66002bc  52   PNLOCKID 257      0  6600288  6000eb   60021a   600257</span><br><span class="line">66002f0  52   PNLOCKID 257      0  66002bc  60017d   60021a   600257</span><br><span class="line">6600324  52   PNLOCKID 257      0  66002f0  6001f5   60021a   600257</span><br><span class="line">6600358  52   PNLOCKID 257      0  6600324  6000ee   60021a   600257</span><br><span class="line">660038c  52   PNLOCKID 257      0  6600358  60017f   60021a   600257</span><br><span class="line">66003c0  52   PNLOCKID 257      0  660038c  6001ea   60021a   600257</span><br><span class="line">66003f4  52   PNLOCKID 257      0  66003c0  6000d4   60021a   600257</span><br><span class="line">6600428  52   PNLOCKID 257      0  66003f4  6001dc   60021a   600257</span><br><span class="line">660045c  52   PNLOCKID 257      0  6600428  600120   60021a   600257</span><br><span class="line">6600490  52   PNLOCKID 257      0  660045c  600241   60021a   600257</span><br><span class="line">66004c4  52   PNLOCKID 257      0  6600490  6000aa   60021a   600257</span><br><span class="line">66004f8  52   PNLOCKID 257      0  66004c4  600186   60021a   600257</span><br><span class="line">660052c  52   PNLOCKID 257      0  66004f8  6001fd   60021a   600257</span><br><span class="line">6600560  52   PNLOCKID 257      0  660052c  6000da   60021a   600257</span><br><span class="line">6600594  52   PNLOCKID 257      0  6600560  600179   60021a   600257</span><br><span class="line">66005c8  52   PNLOCKID 257      0  6600594  6001f3   60021a   600257</span><br><span class="line"></span><br><span class="line">addr     len  type     xid      id link</span><br><span class="line">66005fc  52   PNLOCKID 257      0  66005c8  6000ec   60021a   600257</span><br><span class="line">6600630  52   PNLOCKID 257      0  66005fc  60018b   60021a   600257</span><br><span class="line">6600664  52   PNLOCKID 257      0  6600630  6001f6   60021a   600257</span><br><span class="line">6600698  52   PNLOCKID 257      0  6600664  6000ef   60021a   600257</span><br><span class="line">66006cc  52   PNLOCKID 257      0  6600698  600180   60021a   600257</span><br><span class="line">6600700  52   PNLOCKID 257      0  66006cc  6001f7   60021a   600257</span><br><span class="line">6600734  52   PNLOCKID 257      0  6600700  6000e2   60021a   600257</span><br><span class="line">6600768  52   PNLOCKID 257      0  6600734  60022a   60021a   600257</span><br><span class="line">660079c  52   PNLOCKID 257      0  6600768  600219   60021a   600257</span><br><span class="line">66007d0  44   PERASE   257      0  660079c  600241</span><br><span class="line">6601018  376  HDELETE  257      0  66007d0  60001a   f103     310</span><br><span class="line">6601190  88   DELITEM  257      0  6601018  60001a   60001a   f103     219   1     27</span><br><span class="line">66011e8  140  PBDELETE 257      0  6601190  60001a   12006    77       ffffffff</span><br><span class="line">6601274  532  PBDELETE 257      0  66011e8  60001a   f201     470      ffffffff</span><br><span class="line">6601488  864  PBDELETE 257      0  6601274  60001a   f003     801      ffffffff</span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h5 id="03-35-01-rename-table-所在事务的-提交"><a href="#03-35-01-rename-table-所在事务的-提交" class="headerlink" title="03:35:01 rename table 所在事务的 提交"></a>03:35:01 rename table 所在事务的 提交</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">addr     len  type     xid      id link</span><br><span class="line">6611680  88   ADDITEM  257      0  6611508  60001a   60001a   6a03     219   1     27</span><br><span class="line">66116d8  140  PBINSERT 257      0  6611680  60001a   12201    77       ffffffff</span><br><span class="line">6611764  532  PBINSERT 257      0  66116d8  60001a   6b01     470      ffffffff</span><br><span class="line">6612194  376  HINSERT  257      0  6611764  60001a   6a04     310</span><br><span class="line">661230c  88   ADDITEM  257      0  6612194  60001a   60001a   6a04     219   1     27</span><br><span class="line">6612364  80   PBINSERT 257      0  661230c  60001a   12202    18       ffffffff</span><br><span class="line">66123b4  368  HINSERT  257      0  6612364  60001a   6c01     302</span><br><span class="line">6612524  88   ADDITEM  257      0  66123b4  60001a   60001a   6c01     219   1     27</span><br><span class="line">661257c  200  HUPBEF   257      0  6612524  600002   1504     135</span><br><span class="line">6612644  200  HUPAFT   257      0  661257c  600002   1504     135</span><br><span class="line">661270c  56   BEGCOM   257      0  6612644</span><br><span class="line">6612744  52   CHFREE   257      0  661270c  00006:0000081253 1c</span><br><span class="line">6612778  44   ERASE    257      0  6612744  600241</span><br><span class="line">66127a4  56   COMMIT   257      0  6612778  04/27/2023 03:35:01</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="online分析"><a href="#online分析" class="headerlink" title="online分析"></a>online分析</h2><h5 id="03-35-09-HDR主库-收到背景离线"><a href="#03-35-09-HDR主库-收到背景离线" class="headerlink" title="03:35:09 HDR主库 收到背景离线"></a>03:35:09 HDR主库 收到背景离线</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">03:35:09  SMX thread is exiting</span><br><span class="line">03:35:09  DR: Receive error</span><br><span class="line">03:35:09  dr_prsend thread : asfcode = -25582: oserr = 4: errstr = : Network connection is broken.</span><br><span class="line"> System error = 4.</span><br><span class="line">03:35:09  DR_ERR set to -1</span><br><span class="line">03:35:09  Checkpoint Completed:  duration was 0 seconds.</span><br><span class="line">03:35:09  Thu Apr 27 - loguniq 879, logpos 0x6640390, timestamp: 0xa4b7772c Interval: 54231</span><br><span class="line"></span><br><span class="line">03:35:09  Maximum server connections 354 </span><br><span class="line">03:35:09  Checkpoint Statistics - Avg. Txn Block Time 0.000, # Txns blocked 1, Plog used 895, Llog used 524</span><br><span class="line"></span><br><span class="line">03:35:10  DR: Turned off on primary server</span><br><span class="line">03:35:10  DR: Cannot connect to secondary server</span><br><span class="line">03:40:20  DR: Cannot connect to secondary server</span><br><span class="line">03:40:38  Checkpoint Completed:  duration was 0 seconds.</span><br><span class="line">03:40:38  Thu Apr 27 - loguniq 879, logpos 0x6676468, timestamp: 0xa4b80420 Interval: 54232</span><br><span class="line"></span><br><span class="line">03:40:38  Maximum server connections 354 </span><br><span class="line">03:40:38  Checkpoint Statistics - Avg. Txn Block Time 0.000, # Txns blocked 0, Plog used 144, Llog used 54</span><br></pre></td></tr></table></figure>



<h5 id="03-35-01-HDR从库-宕机"><a href="#03-35-01-HDR从库-宕机" class="headerlink" title="03:35:01 HDR从库 宕机"></a>03:35:01 HDR从库 宕机</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">03:35:01  Assert Failed: Exception Caught. Type: MT_EX_OS, Context: mem</span><br><span class="line">03:35:01  GBase Database Server Version 12.10.FC4G1AEE</span><br><span class="line">03:35:01   Who: Session(221866, gbasedbt@sc-cd-gxz-vas_eb-vcrbt-xlgw-db001-002, 71612, 0x48e60e08)</span><br><span class="line">                Thread(221914, sqlexec, 48e34768, 8)</span><br><span class="line">                File: mtex.c Line: 424</span><br><span class="line">03:35:01   Action: Please notify GBASE Techical Support.</span><br><span class="line">03:35:01  stack trace for pid 14127 written to /gbase/tmp/af.66c27ce5</span><br><span class="line">03:35:01   See Also: /gbase/tmp/af.66c27ce5</span><br><span class="line">03:35:06  Exception Caught. Type: MT_EX_OS, Context: mem</span><br><span class="line">03:35:06  Recursive Exception - Server exiting</span><br><span class="line">03:35:07  Fatal error in ADM VP at mt.c:15076</span><br><span class="line">03:35:07  Unexpected virtual processor termination: pid = 14127, exit status = 0x1.</span><br><span class="line">03:35:07  PANIC: Attempting to bring system down</span><br><span class="line">04:03:32  Parameter&#x27;s user-configured value was adjusted. (ALARMPROGRAM)</span><br><span class="line">04:03:32  GBase Database Server Started.</span><br></pre></td></tr></table></figure>



<h2 id="af分析"><a href="#af分析" class="headerlink" title="af分析"></a>af分析</h2><h5 id="引起宕机的会话"><a href="#引起宕机的会话" class="headerlink" title="引起宕机的会话"></a>引起宕机的会话</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">===========------------- - - - - - -</span><br><span class="line">/gbase/bin/onstat -g ses 221866:</span><br><span class="line">Read-Only (Sec) -- Up 146 days 15:32:45 -- 19028072 Kbytes</span><br><span class="line"></span><br><span class="line">session           effective                            #RSAM    total      used       dynamic </span><br><span class="line">id       user     user      tty      pid      hostname threads  memory     memory     explain </span><br><span class="line">221866   gbasedbt -         -        71612    sc-cd-gx 1        143360     118680     off </span><br><span class="line"></span><br><span class="line">Program :</span><br><span class="line">/gbase/bin/dbaccess</span><br><span class="line"></span><br><span class="line">tid      name     rstcb            flags    curstk   status</span><br><span class="line">221914   sqlexec  48e34768         ---P-R-  1256189680 running-</span><br><span class="line"></span><br><span class="line">Memory pools    count 2</span><br><span class="line">name         class addr              totalsize  freesize   #allocfrag #freefrag </span><br><span class="line">221866       V     4cb9a040         135168     20800      104        16        </span><br><span class="line">221866*O0    V     4cfd4040         8192       3880       2          2         </span><br><span class="line"></span><br><span class="line">name           free       used           name           free       used      </span><br><span class="line">overhead       0          6576           scb            0          144       </span><br><span class="line">opentable      0          5952           filetable      0          1136      </span><br><span class="line">blobio         0          5096           log            0          16536     </span><br><span class="line">temprec        0          22688          keys           0          384       </span><br><span class="line">ralloc         0          23920          gentcb         0          1592      </span><br><span class="line">ostcb          0          2968           sqscb          0          20552     </span><br><span class="line">sql            0          72             hashfiletab    0          552       </span><br><span class="line">osenv          0          2392           sqtcb          0          7784      </span><br><span class="line">fragman        0          336            </span><br><span class="line"></span><br><span class="line">sqscb info</span><br><span class="line">scb              sqscb            optofc   pdqpriority optcompind  directives</span><br><span class="line">4998e4d0         4cfc8028         0        0           0           1         </span><br><span class="line"></span><br><span class="line">Sess       SQL            Current            Iso Lock       SQL  ISAM F.E. </span><br><span class="line">Id         Stmt type      Database           Lvl Mode       ERR  ERR  Vers  Explain    </span><br><span class="line">221866     SELECT         newmin             DR  Not Wait   0    0    9.24  Off        </span><br><span class="line"></span><br><span class="line">Current SQL statement (1) :</span><br><span class="line">  select</span><br><span class="line">    provinceid,callNum,failNum,failtoconfail,auFuncSucc,auFuncTotal,viFuncSucc,</span><br><span class="line">    viFuncTotal from xrc_callstas where dealtime = &#x27;202304270330&#x27; </span><br><span class="line"></span><br><span class="line">Last parsed SQL statement :</span><br><span class="line">  select</span><br><span class="line">    provinceid,callNum,failNum,failtoconfail,auFuncSucc,auFuncTotal,viFuncSucc,</span><br><span class="line">    viFuncTotal from xrc_callstas where dealtime = &#x27;202304270330&#x27; </span><br></pre></td></tr></table></figure>



<h5 id="引起宕机的SQL"><a href="#引起宕机的SQL" class="headerlink" title="引起宕机的SQL"></a>引起宕机的SQL</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">===========------------- - - - - - -</span><br><span class="line">/gbase/bin/onstat -g sql 221866:</span><br><span class="line">Read-Only (Sec) -- Up 146 days 15:32:45 -- 19028072 Kbytes</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Sess       SQL            Current            Iso Lock       SQL  ISAM F.E. </span><br><span class="line">Id         Stmt type      Database           Lvl Mode       ERR  ERR  Vers  Explain    </span><br><span class="line">221866     SELECT         newmin             DR  Not Wait   0    0    9.24  Off        </span><br><span class="line"></span><br><span class="line">Current SQL statement (1) :</span><br><span class="line">  select</span><br><span class="line">    provinceid,callNum,failNum,failtoconfail,auFuncSucc,auFuncTotal,viFuncSucc,</span><br><span class="line">    viFuncTotal from xrc_callstas where dealtime = &#x27;202304270330&#x27; </span><br><span class="line"></span><br><span class="line">Last parsed SQL statement :</span><br><span class="line">  select</span><br><span class="line">    provinceid,callNum,failNum,failtoconfail,auFuncSucc,auFuncTotal,viFuncSucc,</span><br><span class="line">    viFuncTotal from xrc_callstas where dealtime = &#x27;202304270330&#x27; </span><br></pre></td></tr></table></figure>



<h5 id="xrc-callstas-表的-schema"><a href="#xrc-callstas-表的-schema" class="headerlink" title="xrc_callstas 表的 schema"></a>xrc_callstas 表的 schema</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@sc-cd-gxz-vas_eb-vcrbt-xlgw-db001-001:/home/gbasedbt&gt;dbschema -d  newmin -t xrc_callstas  -ss</span><br><span class="line"></span><br><span class="line">DBSCHEMA Schema Utility       GBASE-SQL Version 12.10.FC4G1AEE</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#123; TABLE &quot;gbasedbt&quot;.xrc_callstas row size = 1536 number of columns = 35 index size = 23 ccolnum = 0</span><br><span class="line"> commcol = provinceid,dealtime,callnum,failnum,contifailnum,videonum,audionum,vifunctotal,aufunctotal,vifuncsucc,aufuncsucc,otherfuncsucc,userbgsucc,replayssucc,defbgsucc,caps,capsratio,playchannels,mediachannels,thirdmodtrans,thirdmodsucc,thirdmodfail,prenosupport,xrfileabnormal,callerfreed,calledfreed,callernegofail,callednegofail,negofail,thirdmoderr,mserr,innererr,failtoconfail,nopresupport,abortcontbef &#125;</span><br><span class="line"></span><br><span class="line">create table &quot;gbasedbt&quot;.xrc_callstas </span><br><span class="line">  (</span><br><span class="line">    provinceid char(6) not null ,</span><br><span class="line">    dealtime char(12) not null ,</span><br><span class="line">    callnum integer,</span><br><span class="line">    failnum integer,</span><br><span class="line">    contifailnum integer,</span><br><span class="line">    videonum integer,</span><br><span class="line">    audionum integer,</span><br><span class="line">    vifunctotal varchar(200),</span><br><span class="line">    aufunctotal varchar(200),</span><br><span class="line">    vifuncsucc varchar(200),</span><br><span class="line">    aufuncsucc varchar(200),</span><br><span class="line">    otherfuncsucc integer,</span><br><span class="line">    userbgsucc integer,</span><br><span class="line">    replayssucc integer,</span><br><span class="line">    defbgsucc integer,</span><br><span class="line">    caps integer,</span><br><span class="line">    capsratio decimal(6,2),</span><br><span class="line">    playchannels integer,</span><br><span class="line">    mediachannels integer,</span><br><span class="line">    thirdmodtrans varchar(200),</span><br><span class="line">    thirdmodsucc varchar(200),</span><br><span class="line">    thirdmodfail varchar(200),</span><br><span class="line">    prenosupport integer,</span><br><span class="line">    xrfileabnormal integer,</span><br><span class="line">    callerfreed integer,</span><br><span class="line">    calledfreed integer,</span><br><span class="line">    callernegofail integer,</span><br><span class="line">    callednegofail integer,</span><br><span class="line">    negofail integer,</span><br><span class="line">    thirdmoderr integer,</span><br><span class="line">    mserr integer,</span><br><span class="line">    innererr integer,</span><br><span class="line">    failtoconfail integer,</span><br><span class="line">    nopresupport integer,</span><br><span class="line">    abortcontbef integer</span><br><span class="line">  ) </span><br><span class="line">  fragment by expression </span><br><span class="line">    partition p2023012700 ((dealtime &gt;= &#x27;20230127000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230206000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023020600 ((dealtime &gt;= &#x27;20230206000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230216000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023021600 ((dealtime &gt;= &#x27;20230216000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230226000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023022600 ((dealtime &gt;= &#x27;20230226000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230308000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023030800 ((dealtime &gt;= &#x27;20230308000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230318000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023031800 ((dealtime &gt;= &#x27;20230318000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230328000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023032800 ((dealtime &gt;= &#x27;20230328000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230407000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023040700 ((dealtime &gt;= &#x27;20230407000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230417000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023041700 ((dealtime &gt;= &#x27;20230417000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230427000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023042700 ((dealtime &gt;= &#x27;20230427000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230507000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023050700 ((dealtime &gt;= &#x27;20230507000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230517000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023051700 ((dealtime &gt;= &#x27;20230517000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230527000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023052700 ((dealtime &gt;= &#x27;20230527000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230606000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition p2023060600 ((dealtime &gt;= &#x27;20230606000000&#x27; ) AND </span><br><span class="line">              (dealtime &lt; &#x27;20230616000000&#x27; ) ) in userdbs,</span><br><span class="line">    partition rmd remainder in userdbs</span><br><span class="line">  extent size 4096 next size 4096 lock mode row;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">revoke all on &quot;gbasedbt&quot;.xrc_callstas from &quot;public&quot; as &quot;gbasedbt&quot;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">create index &quot;gbasedbt&quot;.idx_xrc_callstas on &quot;gbasedbt&quot;.xrc_callstas </span><br><span class="line">    (provinceid,dealtime) using btree ;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>





<h5 id="xrc-callstas-表的-pt"><a href="#xrc-callstas-表的-pt" class="headerlink" title="xrc_callstas 表的 pt"></a>xrc_callstas 表的 pt</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line">gbasedbt@sc-cd-gxz-vas_eb-vcrbt-xlgw-db001-001:/home/gbasedbt&gt;oncheck -pt newmin:xrc_callstas </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">TBLspace Report for newmin:gbasedbt.xrc_callstas</span><br><span class="line"></span><br><span class="line">                  Table fragment partition p2023012700 in DBspace userdbs</span><br><span class="line"></span><br><span class="line">    Physical Address               6:197330</span><br><span class="line">    Creation date                  12/18/2022 02:50:02</span><br><span class="line">    TBLspace Flags                 902        Row Locking</span><br><span class="line">                                              TBLspace contains VARCHARS</span><br><span class="line">                                              TBLspace use 4 bit bit-maps</span><br><span class="line">    Maximum row size               1536      </span><br><span class="line">    Number of special columns      7         </span><br><span class="line">    Number of keys                 0         </span><br><span class="line">    Number of extents              1         </span><br><span class="line">    Current serial value           1         </span><br><span class="line">    Current SERIAL8 value          1         </span><br><span class="line">    Current BIGSERIAL value        1         </span><br><span class="line">    Current REFID value            1         </span><br><span class="line">    Pagesize (k)                   2         </span><br><span class="line">    First extent size              2048      </span><br><span class="line">    Next extent size               2048      </span><br><span class="line">    Number of pages allocated      2048      </span><br><span class="line">    Number of pages used           1         </span><br><span class="line">    Number of data pages           0         </span><br><span class="line">    Number of rows                 0         </span><br><span class="line">    Partition partnum              6292055   </span><br><span class="line">    Partition lockid               6292055   </span><br><span class="line"></span><br><span class="line">    Extents                       </span><br><span class="line">         Logical Page     Physical Page        Size Physical Pages</span><br><span class="line">                    0          6:372783        2048       2048</span><br><span class="line"></span><br><span class="line">                  Table fragment partition p2023020600 in DBspace userdbs</span><br><span class="line"></span><br><span class="line">    Physical Address               6:140890</span><br><span class="line">    Creation date                  12/28/2022 02:50:02</span><br><span class="line">    TBLspace Flags                 902        Row Locking</span><br><span class="line">                                              TBLspace contains VARCHARS</span><br><span class="line">                                              TBLspace use 4 bit bit-maps</span><br><span class="line">    Maximum row size               1536      </span><br><span class="line">    Number of special columns      7         </span><br><span class="line">    Number of keys                 0         </span><br><span class="line">    Number of extents              1         </span><br><span class="line">    Current serial value           1         </span><br><span class="line">    Current SERIAL8 value          1         </span><br><span class="line">    Current BIGSERIAL value        1         </span><br><span class="line">    Current REFID value            1         </span><br><span class="line">    Pagesize (k)                   2         </span><br><span class="line">    First extent size              2048      </span><br><span class="line">    Next extent size               2048      </span><br><span class="line">    Number of pages allocated      2048      </span><br><span class="line">    Number of pages used           122       </span><br><span class="line">    Number of data pages           121       </span><br><span class="line">    Number of rows                 362       </span><br><span class="line">    Partition partnum              6291845   </span><br><span class="line">    Partition lockid               6292055   </span><br><span class="line"></span><br><span class="line">    Extents                       </span><br><span class="line">         Logical Page     Physical Page        Size Physical Pages</span><br><span class="line">                    0          6:507070        2048       2048</span><br><span class="line"></span><br></pre></td></tr></table></figure>







<h5 id="af堆栈记录"><a href="#af堆栈记录" class="headerlink" title="af堆栈记录"></a>af堆栈记录</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line">03:35:01  Context ptr = 0x000000000210bf00</span><br><span class="line">03:35:01  Siginfo ptr = 0x000000000210c030</span><br><span class="line">03:35:01  Reg  0(R8)      0x000000004cf08208 Reg  1(R9)      0x0000000000000001</span><br><span class="line">03:35:01  Reg  2(R10)     0x000000000000000e Reg  3(R11)     0x0000000000000001</span><br><span class="line">03:35:01  Reg  4(R12)     0x000000004cf4fe08 Reg  5(R13)     0x00000000fffffffd</span><br><span class="line">03:35:01  Reg  6(R14)     0x000000004cfbc510 Reg  7(R15)     0x000000004cfced58</span><br><span class="line">03:35:01  Reg  8(RDI)     0x0000000000000000 Reg  9(RSI)     0x000000004cfd0fc0</span><br><span class="line">03:35:01  Reg 10(RBP)     0x0000000000000001 Reg 11(RBX)     0x000000004cf4f6f0</span><br><span class="line">03:35:01  Reg 12(RDX)     0x000000004cfcee88 Reg 13(RAX)     0x000010000799001d</span><br><span class="line">03:35:01  Reg 14(RCX)     0x00000000006000aa Reg 15(RSP)     0x000000004cf08250</span><br><span class="line">03:35:01  Reg 16(RIP)     0x00000000008525b1 Reg 17(EFL)     0x0000000000010202</span><br><span class="line">03:35:01  Reg 18(CSGSFS)  0x0000000000000033 Reg 19(ERR)     0x0000000000000004</span><br><span class="line">03:35:01  Reg 20(TRAPNO)  0x000000000000000e Reg 21(OLDMASK) 0x0000000000000000</span><br><span class="line">03:35:01  Reg 22(CR2)     0x0000100007990025</span><br><span class="line">03:35:01  </span><br><span class="line">03:35:01  GBase Database Server Version 12.10.FC4G1AEE Software Serial Number AAA#B000000</span><br><span class="line"></span><br><span class="line">03:35:01  Assert Failed: Exception Caught. Type: MT_EX_OS, Context: mem</span><br><span class="line">03:35:01   Who: Session(221866, gbasedbt@sc-cd-gxz-vas_eb-vcrbt-xlgw-db001-002, 71612, 0x48e60e08)</span><br><span class="line">		Thread(221914, sqlexec, 48e34768, 8)</span><br><span class="line">		File: mtex.c Line: 424</span><br><span class="line">03:35:01   Action: Please notify GBASE Techical Support.</span><br><span class="line">03:35:01  SHM Globals and Master Pool/Master Block Adresses:</span><br><span class="line"></span><br><span class="line">03:35:01  shmcb =           0x000000004405a618</span><br><span class="line">03:35:01  rhead =           0x00000000440c5800</span><br><span class="line">03:35:01  pool list =       0x000000004405a6f0</span><br><span class="line">03:35:01  block pool list = 0x00000000440bfef8</span><br><span class="line">03:35:01  TRANSP =          0x0000000048e60e08</span><br><span class="line">03:35:01  PARTP =           0x000000004a177a18</span><br><span class="line">03:35:01  PARTNP =          0x000000004a177b28</span><br><span class="line">03:35:01  OPENP =           0x000000004ceb3428</span><br><span class="line">03:35:01  FILEP =           0x000000004cf14ac8</span><br><span class="line">03:35:01  Raw hex dump of stack located in /gbase/tmp/af.66c27ce5.rawstk</span><br><span class="line">03:35:01  Stack for thread: 221914 sqlexec</span><br><span class="line"></span><br><span class="line"> base: 0x000000004cee9000</span><br><span class="line">  len:   135168</span><br><span class="line">   pc: 0x00000000015466cf</span><br><span class="line">  tos: 0x000000000210abf0</span><br><span class="line">state: running</span><br><span class="line">   vp: 8</span><br><span class="line"></span><br><span class="line">0x00000000015466cf (oninit) afstack</span><br><span class="line">0x0000000001548d67 (oninit) afhandler</span><br><span class="line">0x000000000154906e (oninit) affail_interface</span><br><span class="line">0x000000000154d732 (oninit) mt_ex_throw_sig</span><br><span class="line">0x00000000014e43d0 (oninit) afsig_handler</span><br><span class="line">0x00007f28e8c2a630 (Linux) &lt;signal frame&gt;</span><br><span class="line">0x00000000008525b1 (oninit) opfr_term</span><br><span class="line">0x0000000000852e1a (oninit) opfr_expr</span><br><span class="line">0x00000000008534a7 (oninit) fr_rem</span><br><span class="line">0x0000000000853a0d (oninit) opfr_remove</span><br><span class="line">0x00000000008558fd (oninit) opinit</span><br><span class="line">0x0000000000858af3 (oninit) op_opinit</span><br><span class="line">0x000000000085ab33 (oninit) sqoptim</span><br><span class="line">0x0000000000ab74a7 (oninit) bldstructs</span><br><span class="line">0x0000000000aca453 (oninit) sqcmd</span><br><span class="line">0x0000000000acad7a (oninit) sq_cmnd</span><br><span class="line">0x0000000000acae04 (oninit) sq_prepare</span><br><span class="line">0x0000000000ba5138 (oninit) sqmain</span><br><span class="line">0x00000000016520d4 (oninit) spawn_thread</span><br><span class="line">0x0000000001542bc3 (oninit) th_init_initgls</span><br><span class="line">0x0000000001506a5f (oninit) startup</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> ucontext: 0x000000000210bf00</span><br><span class="line">  siginfo: 0x000000000210c030</span><br><span class="line">           si_signo: 11  si_code: 1   si_errno: 0 si_pid: 127467557 si_uid: 4096 </span><br><span class="line">           si_addr: 0x0000100007990025 si_value: 0x0000000000000000  si_fd: 0</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">03:35:01   See Also: /gbase/tmp/af.66c27ce5</span><br><span class="line"></span><br><span class="line">---------------------------------</span><br><span class="line">Begin System Alarm Program Output</span><br><span class="line">---------------------------------</span><br><span class="line"></span><br><span class="line">Assertion Failure Type:	FAILURE</span><br><span class="line">Host Name:		sc-cd-gxz-vas_eb-vcrbt-xlgw-db001-002</span><br><span class="line">Database Server Name:	hdr2</span><br><span class="line">Time of failure:	Thu Apr 27 03:35:01 CST 2023</span><br><span class="line">AF file:		/gbase/tmp/af.66c27ce5</span><br><span class="line">Shared memory file:	None</span><br><span class="line">System Blocking:	OFF</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="目前宕机原因推断"><a href="#目前宕机原因推断" class="headerlink" title="目前宕机原因推断"></a>目前宕机原因推断</h2><ul>
<li>宕机应该是由于由于主节点rename提交后系统并不存在xrc_callstas表。</li>
<li>HDR节点在rename提交的时间上执行了select导致HDR宕机。</li>
</ul>
<h2 id="后续测试和工作内容"><a href="#后续测试和工作内容" class="headerlink" title="后续测试和工作内容"></a>后续测试和工作内容</h2><ul>
<li>搭建模拟环境测试复现HDR宕机。</li>
<li>找研发查看源码File: mtex.c Line: 424。</li>
<li>找研发帮忙进一步确定和解问题。</li>
</ul>
<h2 id="目前整改建议"><a href="#目前整改建议" class="headerlink" title="目前整改建议"></a>目前整改建议</h2><ul>
<li>建议不要再生产时间段修改表结构。</li>
<li>修改表结构需要有单独的变更维护时间窗口。</li>
</ul>
<h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><h5 id="日志类型"><a href="#日志类型" class="headerlink" title="日志类型"></a>日志类型</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">BLDCL		构建tblspace。</span><br><span class="line">PTCOLUMN	将特殊列添加到片段中。</span><br><span class="line">CHALLOC		区块范围分配。</span><br><span class="line">PTEXTEND	Tblspace扩展。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">PTRENAME	重命名表。</span><br><span class="line"></span><br><span class="line">PNLOCKID  	更改表空间锁定。</span><br><span class="line">UNIQID		当一个新的SERIAL值被分配给一行时记录。</span><br><span class="line">PERASE		预擦旧文件。</span><br><span class="line">HDELETE		删除主行。</span><br><span class="line">DELITEM		从索引中删除项目。</span><br><span class="line">PBDELETE	删除tblspace Blob页。</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h5 id="收集生产onlog"><a href="#收集生产onlog" class="headerlink" title="收集生产onlog"></a>收集生产onlog</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">onlog -n 879 &gt; 879min ;</span><br><span class="line">onlog -n 879 -l &gt; 879max ;</span><br><span class="line">tar zcvf 879.tar.gz 879min 879max </span><br><span class="line"></span><br><span class="line">oncheck -pt 0x60001a &gt; 60001a.pt</span><br><span class="line"></span><br></pre></td></tr></table></figure>




 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Bug/" rel="tag">Bug</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%AE%95%E6%9C%BA/" rel="tag">宕机</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
    <article
  id="post-锁表故障时抓取锁相关信息"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2023/04/24/%E9%94%81%E8%A1%A8%E6%95%85%E9%9A%9C%E6%97%B6%E6%8A%93%E5%8F%96%E9%94%81%E7%9B%B8%E5%85%B3%E4%BF%A1%E6%81%AF/"
    >锁表故障时抓取锁相关信息</a> 
</h2>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2023/04/24/%E9%94%81%E8%A1%A8%E6%95%85%E9%9A%9C%E6%97%B6%E6%8A%93%E5%8F%96%E9%94%81%E7%9B%B8%E5%85%B3%E4%BF%A1%E6%81%AF/" class="article-date">
  <time datetime="2023-04-24T03:43:47.000Z" itemprop="datePublished">2023-04-24</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/GBase8s/">GBase8s</a>
  </div>
   
    </div>
      
    <div class="article-entry" itemprop="articleBody">
       
  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">DIR=`date &quot;+%Y%m%d_%H%M%S&quot;`</span><br><span class="line">mkdir -p /tmp/lock_problem/$&#123;DIR&#125;</span><br><span class="line">cd  /tmp/lock_problem/$&#123;DIR&#125;</span><br><span class="line"></span><br><span class="line">i=1</span><br><span class="line">while [ $i -le 10 ]</span><br><span class="line">do</span><br><span class="line">	echo &quot;$&#123;i&#125;---------------------------&quot;</span><br><span class="line">	onstat -k &gt; k_$&#123;i&#125;</span><br><span class="line">	onstat -u &gt; u_$&#123;i&#125;</span><br><span class="line">	onstat -g ses 0 &gt; ses_$&#123;i&#125;</span><br><span class="line">	let i=$i+1</span><br><span class="line">	sleep 1</span><br><span class="line">done</span><br><span class="line"></span><br><span class="line">echo &quot;unload to /tmp/lock_problem/$&#123;DIR&#125;/tables.list select hex(partnum),* from systabnames&quot;|dbaccess sysmaster </span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>出问题的时候，跑一下这个脚本抓取锁故障相关信息。会跑1分钟，结束后把&#x2F;tmp&#x2F;lock_problem&#x2F;目录打包一下发出来。</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/lock/" rel="tag">lock</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E4%BF%A1%E6%81%AF%E6%94%B6%E9%9B%86/" rel="tag">信息收集</a></li></ul>

    </footer>
  </div>

   
   
  
</article>

    
  </article>
  

  
  <nav class="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/4/">上一页</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><span class="page-number current">5</span><a class="page-number" href="/page/6/">6</a><a class="extend next" rel="next" href="/page/6/">下一页</a>
  </nav>
  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2023-2024
        <i class="ri-heart-fill heart_icon"></i> Wang Wei
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ww.ico" alt="朝花夕拾"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->

<script src="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.staticfile.org/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.staticfile.org/clipboard.js/2.0.10/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>